ngx-modialog: Modal not showing when used with Bootstrap V4
I spent some time wondering why the modal would not show on screen, now I found out and I want to share my insights in case anyone has the same problem.
The reason was a breaking change in Bootstrap 4.0.0-alpha.6. In earlier Versions, class=“fade in” on the modal caused it to a) be hidden and b) smoothly appear. It seems that the “in” class has now been renamed to “show”. angular2-modal gives its element the classes “fade in” however, so they just disappear.
Workaround
Override styles:
.fade.in {
opacity: 1;
}
.modal.in .modal-dialog {
-webkit-transform: translate(0, 0);
-o-transform: translate(0, 0);
transform: translate(0, 0);
}
.modal-backdrop.in {
opacity: 0.5;
}
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 83
- Comments: 27 (2 by maintainers)
I can confirm that the same issue occurs, however I had to include important tags in order to override the default css. Here’s the revised version.
OK @jsnkelvin @shabbir-dhangot:
I managed to get rid of the delay given the hint from my workaround. The
combineLatestRXJS method waits for amyAnimationEnd$from both thebackdropandcontainer. The issue with @dimejy2’s CSS workaround looks like it prevents the animation on themodal-backgroundby setting the opacity to 0.5 for both.fadeand.fade .in. What is working for me is @nbckr’s original snippet:And a plunker: http://plnkr.co/edit/b44cBG0LdXTS7jMlXsfA
@shlomiassaf, it looks like the only changes for bootstrap 4 (alpha 6 at least) is to update any instances of the
inclass toshowand this workaround will no longer be necessary. I can create a PR if you’re interested.Did you add this to your HTML?
Thats currently required for v4
Thanks for the headsup @nielsboecker as this is also unsurprisingly a problem with bootstrap 3 framework… to get modal to show use following scss based on Niels’ post:
… and rather use component to open modal as the templateRef doesn’t seem to work… come on ngx-bootstrap developers you claim your ngx framework is re bootstrap backwards compatible 😃
I have this working with Bootstrap 4.3.1
.fade.in { opacity: 1 !important; }
.modal.in .modal-dialog { -webkit-transform: translate(0, 0) !important; -o-transform: translate(0, 0) !important; transform: translate(0, 0) !important; }
.modal-backdrop .fade .in { opacity: 0.5 !important; }
.modal-backdrop.fade { opacity: 0.5 !important; }
This is very similar to what you see above BUT the “!important” attribute has been added to some of the items.
@dimejy2 code works well, but there is some delay on background fading when closing the modal. maybe because the fade out got replaced too.
is there any way to fix that? thanks!
@JoshuaCaputo Yes, But there is nothing to do with curtain. Even if you remove class (curtain), the modal will appear. If we use the given modal examples in Bootstrap 4, it works. But when we use the modal examples for Bootstrao 4.1.3, it doesn’t works. Please raise a ticket for this issue.
Also experiencing this issue: 4.1.3/css/bootstrap.min.css 4.1.3/js/bootstrap.min.js
The workaround does seem to fix this confict. mabe fade should be something not some widespread… it sort of curtains…
class="modal curtain"@shabbir-dhangot we’re using Angular2-modal as it allows you to create modals from TypeScript with fluent API. That’s not possible with ng-bootstrap’s version.
@shlomiassaf here is a plunker showing the problem: http://plnkr.co/edit/b44cBG0LdXTS7jMlXsfA.
I suspect this issue is related to #217. The delay noted in this ticket appears to be caused by the animation effect callback never being triggered as described in the other ticket; this also causes the modal-open class to be “stuck” on the
<body>.As a workaround for the delay, you can comment out a few lines in modal.js and it works (albeit without animation):
Edit: use code tags and add workaround
I can confirm the issue and the workaround. With Boostrap 4.0.0-alpha.6, calling the
openmethod makes the application appear to hang, scrolling is disabled but the screen content does not change. This is due to the modal being present but not visible.