Skip to content

Modal "hidden" event is firing while the modal is still visible #35599

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
3 tasks done
ghost opened this issue Dec 24, 2021 · 6 comments
Closed
3 tasks done

Modal "hidden" event is firing while the modal is still visible #35599

ghost opened this issue Dec 24, 2021 · 6 comments
Labels
js stale Closed as stale v5

Comments

@ghost
Copy link

ghost commented Dec 24, 2021

Prerequisites

Describe the issue

It appears that "hidden.bs.modal" events are raised on modals before the modal is actually hidden. I have created a simple repro at JSFiddle, linked below. This code creates a modal, listens for "hidden.bs.modal" events and shows an alert when the event is received. The alert appears and the modal is still visible underneath.

Reduced test cases

https://jsfiddle.net/om8d0swb/

What operating system(s) are you seeing the problem on?

Windows

What browser(s) are you seeing the problem on?

Chrome, Microsoft Edge

What version of Bootstrap are you using?

5.1.3

@chirag3003
Copy link

@kc-jeffk everything is working as it should .
When the event you are using is triggered, first the function passed in the event listener is executed then the actual process is executed . So when the modal close event is triggered your alert function is executed first the the modal close function is triggered .

@ghost
Copy link
Author

ghost commented Dec 24, 2021

Hello, @chirag3003.

It sounds like you are describing the "hide.bs.modal" event, not the "hidden.bs.modal" event. The second is what the code is listening for. According to the documentation for the "hidden.bs.modal" event, "This event is fired when the modal has finished being hidden from the user (will wait for CSS transitions to complete)." Perhaps there is some nuance about what it means to complete a transition that I do not understand, but the documentation does not seem to match the behavior.

Thanks.

@florianlacreuse
Copy link
Contributor

In order to get the CSS transitions, you need to add .fade on .modal, see the live demo.

Your example fixed: https://codepen.io/florianlacreuse/pen/YzrLROE

@ghost
Copy link
Author

ghost commented Jan 6, 2022

So, the hidden event is raised after the modal is actually hidden if and only if there is a transition. Without a transition, it is raised before the modal is hidden, and this is the expected behavior. TBH, I find the inconsistency confusing. But if this is the way it's supposed to work, so be it.

@ghost ghost closed this as completed Jan 6, 2022
@florianlacreuse
Copy link
Contributor

I'm just trying to help about fade and transition, may be you should re-open rhe issue and wait for an official response from a member of the BS team?

@ghost
Copy link
Author

ghost commented Jan 14, 2022

Sure, I can do that. This isn't a big issue for me, just confusing and, as you both said, easily worked around by using transitions.

@ghost ghost reopened this Jan 14, 2022
@mdo mdo added the stale Closed as stale label Apr 10, 2025
@mdo mdo closed this as not planned Won't fix, can't repro, duplicate, stale Apr 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
js stale Closed as stale v5
Projects
None yet
Development

No branches or pull requests

4 participants