ng-bootstrap: scrollable doesn't work on modals with component as content
Bug 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
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 2
- Comments: 16 (9 by maintainers)
Commits related to this issue
- fix(modal): cmpt based content was not scrollable In `5.0.0` we introduced the bootstrap scrollable content feature. This behaviour appears to be broken with modal that have content generated from a ... — committed to benouat/ng-bootstrap by deleted user 5 years ago
- fix(modal): cmpt based content was not scrollable In `5.0.0` we introduced the bootstrap scrollable content feature. This behaviour appears to be broken with modal that have content generated from a ... — committed to benouat/ng-bootstrap by deleted user 5 years ago
- fix(modal): cmpt based content was not scrollable In `5.0.0` we introduced the bootstrap scrollable content feature. This behaviour appears to be broken with modal that have content generated from a ... — committed to benouat/ng-bootstrap by deleted user 5 years ago
- fix(modal): cmpt based content was not scrollable In `5.0.0` we introduced the bootstrap scrollable content feature. This behaviour appears to be broken with modal that have content generated from a ... — committed to benouat/ng-bootstrap by deleted user 5 years ago
- fix(modal): cmpt based content was not scrollable (#3286) In `5.0.0` we introduced the bootstrap scrollable content feature. This behaviour appears to be broken with modal that have content generate... — committed to ng-bootstrap/ng-bootstrap by deleted user 5 years ago
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-scrollablerule comes withoverflow: hidden, which is not enough if I’m changingmodal-bodywith 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
idand then in the submit buttin, set that the buttons form attribute to that value. Sorry to have bothered.@luisVargasGu 100% that did it
Guys
This works, you just need to change ‘[style.overflow]’: ‘“hidden”’ to ‘[style.overflow]’: ‘“auto”’
Perfect @benouat ! You rock! Thanks a lot.
Thanks @benouat , but I don’t think adding these two styles on the modal content component fixes anything. Unless I miss something in your instructions. Could you provide an example where this workaround works?
Here’s a workaround I found (but it’s a bit fragile, and I suck at CSS):
Replace, in the template of my modal content component
by