scrollable doesn't work on modals with component as content
See original GitHub issueBug description:
When using a component as the content of a modal rather than a template, with the scrollable option set to true, the modal body doesn’t scroll.
The CSS magic apparently doesn’t work when an additional element (the host element of the component) is inserted between the .modal-content
and the .modal-body
, but I’m so bad at CSS that I can’t even find a workaround.
Link to minimally-working StackBlitz that reproduces the issue:
https://stackblitz.com/edit/angular-rekfnj?file=app/modal-component.ts
Versions of Angular, ng-bootstrap and Bootstrap:
Angular: 8.1 ng-bootstrap: 5.0.0-rc.1 Bootstrap: 4.3.1
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:16 (9 by maintainers)
Top Results From Across the Web
Bootstrap modal, scrollable does not work
I changed it to modal-dialog > modal-content > modal-body > form . modal-body should be direct child of modal-content , rest is fine....
Read more >Modal Not Scrollable
Hi there, All the modals when open up are not scrollable on any screen size if the modal height is big. Please help...
Read more >Modal
Modals are built with HTML, CSS, and JavaScript. They're positioned over everything else in the document and remove scroll from the <body> so...
Read more >Modal - Angular powered Bootstrap
You can pass an existing component as content of the modal window. In this case, if you're still using Angular 8 or older,...
Read more >Modal is not scrollable
Hi Guys, I had a component for modal... My other modal is scrollable but this one is not... I tried to check each...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sorry to comment on a closed thread, but I got here via Google and I was dealing with this specific bug, albeit my case was more complicated due to injection of another Component inside the one component my modal opens up. This thread showed me a simple fix, so I’ll leave it here. Thanks everyone above for the help.
Angular: 11.2.5 ng-bootstrap: 9.1.2 Bootstrap: 4.5.0
Host component just needed that
[style.overflow]: "auto"
. The defaultngb-modal-window .component-host-scrollable
rule comes withoverflow: hidden
, which is not enough if I’m changingmodal-body
with new content after I already opened the modal with the host component. So, my final host component becomes:[UPDATE]: on a side note, I also found out that mine and @jnizet bug must be caused by missing a
<div class="modal-content" modal>
wrapping up header, body & footer as indicated by https://getbootstrap.com/docs/4.6/components/modal/#scrolling-long-content. After fixing that, no host style was needed.@benouat thanks for taking the time to reply. According to my package.json I am now running Angular 8.2.14 and @ng-bootstrap/ng-bootstrap 5.3.0 and it wasn’t working. But in an effort to really ensure I wasn’t doing something stupid, I tried something and it now works.
I was wrapping my components html in <form> </form> (so that the submit button in the footer works as expected), and that is what breaks it. The solution was to give the form an
id
and then in the submit buttin, set that the buttons form attribute to that value. Sorry to have bothered.