-
-
Notifications
You must be signed in to change notification settings - Fork 79k
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
Can't hide modal before it is "shown?" #34213
Comments
Possibly a duplicate of #34055? |
Try to use the following scripts on your test:
I suppose it will work fine. (and please feedback us) |
or by genlty initializing |
This is a solution to hide() method not working when fade css class is used. It is unnecessary to check weather the modal is transitioning before hiding the modal. Issue: twbs#34213
@GeoSot I'm afraid #34085 wouldn't fix that. The problem here is that while the modal is transitioning it just returns from calls to Simply removing Not sure if we really should do something here at all. It's not like the transitions take forever and how often does it happen that someone does a misclick and is able to react fast enough to really make use of that. Even if so, you can simply click a few times and it would eventually close. Also with the check for Here is the OPs code with his fix from #34232 applied https://jsfiddle.net/z6p0oujt/. IMO the improvement from the that fix is negligible as it requires a certain timing to make use of the change at all. (You have to wait for the backdrop before you click and it saves you some ms that is needed to fully show the modal.) If it happens on a frequent basis, one can simply remove the fade class so it wouldn't be a problem at all. |
But it is related to #33727 . Right? |
It took me a while to figure out why the demo I posted wasn't working with the updated fix, then I realized a small change to the CSS was required for it to work. Also, this was just a simple demo of one use case, least complex example that could think of. The reason I need hide to respond instantly is I want to hide the modal when user navigates back in the browser. I do that by modifying the URL (with In the case that user closes modal in the normal way (other than back navigation) I call |
@binseq I faced a similar problem with offcanvas recently. I ended up listening once for the "shown" event before calling function forceHide(el){
el.addEventListener('shown.bs.modal', () => bootstrap.Modal.getInstance(el).hide(), {once: true});
} Though that wouldn't help get rid of the small delay, at least |
Yes, somewhat. The problem is a bit different but it got something to do with transitions being asynchronous and methods are called in a synchronous way. IMO, we would need to implement some way of cancelling transitions or to automatically queue code that is called during the component being busy. |
Hi team, I want to add my support for a resolution to this issue. My use case is that I display a table of items, and clicking on at item will display a large modal with an edit screen. The content of the modal gets loaded asynchronously on 'show.bs.modal'. However, if loading the modal content fails (e.g. session has timed out, or permission error) then I want to display a different, smaller modal with an error message. Since I can't display two modals at once, I have to close the first one. But if the error happens quickly, before the main modal has finished transitioning, then I can't close it. I would very much like a single method to both hide an already open modal and also hide it immediately if it's in the middle of being shown. You might wonder why I don't just display the error message in the main modal... It's because that one has a custom toolbar and buttons intended for editing, so if I was going to show an error message then I would want to hide these elements, and then reveal them again if the modal gets re-opened. The other workaround is to just manually hide the entire modal. Either way feels hacky. |
In Bootstrap 5, calling
Modal.hide()
has no effect until modal is "shown" (it works as expected if thefade
css class is removed).Suppose you have list of items and a single modal. When you click on each item, details about that item are shown in the modal, but you accidentally clicked the wrong item, so you want to quickly cancel by clicking the backdrop while it's fading in. Currently you cannot do that. You have to wait until the wrong item is shown to you before you can close it.
Is there a way around this?
Maybe there should be an optional parameter,
Modal.hide(force=true)
.Without proposed fix: https://jsfiddle.net/o7wdt6r5/
With proposed fix: https://jsfiddle.net/fgyuerLo/
The text was updated successfully, but these errors were encountered: