Skip to content

backdrop issue with nested modals #6686

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
SusanneEmineo opened this issue Sep 25, 2024 · 6 comments
Closed

backdrop issue with nested modals #6686

SusanneEmineo opened this issue Sep 25, 2024 · 6 comments

Comments

@SusanneEmineo
Copy link

SusanneEmineo commented Sep 25, 2024

Bug description:

When working with nested modals, the backdrop disappears when the first modal is hidden, even though there are still modals open. Following disappears in the html, thus the background blurring is lost:
<bs-modal-backdrop class="modal-backdrop fade show"></bs-modal-backdrop>

The issue is actually visible in the demo of the current ngx-bootstrap version: https://valor-software.com/ngx-bootstrap/#/components/modals#service-nested: Open first modal -> Open second modal -> Close self / Close first modal (in either case)

I tried a manual workaround counting levels of modals and calling this.bsModalService._showBackdrop(); in case there are still modals open, but that does not work.

Versions of ngx-bootstrap, Angular, and Bootstrap:

ngx-bootstrap: 18.0.2

Angular: 18.2.0

Bootstrap: 5.3.3

Build system: Angular CLI

Expected behavior

I expect the backdrop to remain until the last modal ist hidden.

@dur00s
Copy link

dur00s commented Sep 26, 2024

Experiencing the same, only difference is that we are using Angular 18.1.0

@rogerwilcos83
Copy link

I can confirm I have the same issue. I am on ngx-bootstrap 18.0.2, angular 18.2.5. Any workaround would be appreciated if available.

@frenzymind
Copy link

Same here

@Gillardo
Copy link
Contributor

Gillardo commented Oct 9, 2024

same issue

@serhatuysal
Copy link

serhatuysal commented Oct 9, 2024

I solved it this way for now, and it seems to be working.

openModal(
content: any,
options?: ModalOptions
): BsModalRef {
const modal = this.bsModalService.show(
content,
{
class: 'modal-sm',
animated: false,
backdrop: 'static',
...options
},
);
modal.onHide.subscribe(() => {
debugger;
const openModals = this.bsModalService.getModalsCount();
if (openModals > 0) {
this.addCustomBackdrop();
} else {
this.removeCustomBackdrop();
}
});
return modal;
}
addCustomBackdrop() {
const backdrop = this.renderer.createElement('bs-modal-backdrop');
this.renderer.addClass(backdrop, 'modal-backdrop');
this.renderer.addClass(backdrop, 'show');
this.renderer.appendChild(document.body, backdrop);
}

removeCustomBackdrop() {
const backdrop = document.querySelector('bs-modal-backdrop');
if (backdrop) {
backdrop.remove();
}
}

@lexasq
Copy link
Contributor

lexasq commented Oct 16, 2024

Hi. Today was introduced version 18.1.0 and fix for this was a part of it. Thanks for reporting!

@lexasq lexasq closed this as completed Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants