-
-
Notifications
You must be signed in to change notification settings - Fork 178
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
Fix modal overlay handling. #163
Conversation
Interesting find, thanks ;) |
Hey the overlay doesn't seem to close at all after opened second modal, I fixed that. |
Ah, thanks for fixing that! |
Looking at your fix, I'm not sure if the reference counting is working correctly. When ref-counting, the count should update every time either With your changes, the count is incremented after the guard: createOverlay = function() {
if ( modalOverlayRefCount > 1 ) { return; }
modalOverlayRefCount += 1;
// create the overlay
}
removeOverlay = function() {
if ( modalOverlayRefCount === 0 ) { return; }
modalOverlayRefCount -= 1;
// remove the overlay
} Consider the following sequence of
What I need is this:
This second sequence removes the overlay only when the last createOverlay = function() {
modalOverlayRefCount += 1;
if ( modalOverlayRefCount !== 1 ) { return; }
// this is a 0-1 transition
// create the overlay
}
removeOverlay = function() {
modalOverlayRefCount -= 1;
if ( modalOverlayRefCount !== 0 ) { return; }
// this is a 1-0 transition
// remove the overlay
} |
I don't exactly know what you need, my changes make sure it works and I tested several times, but I might consider reverting to previous code revision. |
I'd like the backdrop to stay up while modals are on the page. I've created some jsfiddles to demonstrate. Here is v2.0.15 demonstrating the issue: Here is the same code but with my fix: Here is the same code but with your fix that is currently in v2.0.17: Above you said:
Would you mind putting together a jsFiddle to show me the issue? I can look into it. Thanks for your time and this project - it's awesome! |
Your script example:
This is not required, also you don't have to initialize modals on click, you just initialize button/modal like I wrote in the documentation:
All my examples here work flawless. I don't understand why you need to complicate things. That's how it is supposed to be used. |
I think firstModalEl.addEventListener('hide.bs.modal', openSecondModal, false); |
RE:
The RE: #163 (comment) My actual code uses React. The HTML is appended to the page as part of rendering a React component. The use case is that I have some action that pops a modal. If the user is not signed in, an authentication modal is popped first to prompt the user to sign in. After the user signs in on the authentication modal, the original modal is popped. The original modal is popped in the The reason this behavior is occurring is explained in #30:
I have not looked at your examples. I will look to see if you have that case. I will also pull together a jsfiddle using normal bootstrap JS to see if it's an issue there. I'll also look at the examples with my changes and see if I can see the issue you pointed above. If there's a better way to pop a modal after another modal has been hidden, let me know. Thanks |
I will try to recreate your use case with the fiddle you've made, I want to have it fixed for everybody not just me, but the way you do things aren't (at least to my mind) proper JavaScript. I mean every time you click the button you create a new instance of Modal, over and over, it's gonna blow up somewhere. I have little to no experience with React, but that's what I understand from your example. |
RE: #163 (comment) I looked at your examples with my changes. I see that you are using Line 500 in 168c77c
Clicking this button causes dismissHandler = function(e) {
var clickTarget = e[target];
if ( open && (clickTarget[parentNode][getAttribute](dataDismiss) === component
|| clickTarget[getAttribute](dataDismiss) === component
|| (clickTarget === modal && self[backdrop] !== staticString) ) ) {
self.hide(); relatedTarget = null;
e.preventDefault();
}
};
I'm not sure what the behavior would be for normal bootstrap JS. I'll pull together a jsfiddle for that. On a cursory look at normal bootstrap v4 JS, I do see that the This is different than bootstrap.native where, as explained in #30, the Changing bootstrap.native to match normal bootstrap's behavior to fire the |
Here's an example using normal bootstrap JS: It works. That is, the overlay animates away and back again between the modals and finally away after dismissing the last modal. |
Our code is supposed to do better in this case. I don't want to hide the overlay while closing visible modal and opening new one. That's what I had in mind from the start. The thing is, your |
RE:
Why do different than bootstrap? I thought this library was suppose to match the behavior of standard bootstrap. Is that not the case? |
Lastly, the issue here is that the code in |
Just stumbled upon this: I'll likely switch to this as soon as it's available. In the meantime, I'll stick with my fork of this library barring a better fix that is consistent with normal bootstrap behavior. |
In my mind doing things exactly like original plugins was a bit of a tinkering. I always wanted to make it better in some ways, because with plain JavaScript you can, still I think some of our functionality here was later added to the original plugins because it was a better way IMO. |
OK I got this thing to work with the events as in your example, it works exactly the same as with jQuery version. But it also works the way I've set the first example. Be prepared to test in a couple of hours. |
@dtognazzini go check the master code. |
@thednp Finally getting around to this now. NPM can't find it version 2.0.18. Did you push? |
@thednp master is working well. Thanks! |
Addresses #162.
These changes wrap the
createOverlay
andremoveOverlay
methods with reference counts to ensure thatcreateOverlay
/removeOverlay
is only called when there are no other modals managing the overlay.I also removed the bit about removing the "show" class from the overlay in
hide
since the overlay is going to be removed from the DOM byremoveOverlay
anyway if the ref-count hits zero.