-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Open modal multiple times and closing it leaves behind the dark overlay permanently #1647
Comments
Problem is that the lean-overlay is not reused if it exists: Following: The generated html after opening the modal 4 times. <div class="lean-overlay" id="materialize-lean-overlay-1" style="z-index: 1002; display: block; opacity: 0.5;"></div>
<div class="lean-overlay" id="materialize-lean-overlay-2" style="z-index: 1004; display: block; opacity: 0.5;"></div>
<div class="lean-overlay" id="materialize-lean-overlay-3" style="z-index: 1006; display: block; opacity: 0.5;"></div>
<div class="lean-overlay" id="materialize-lean-overlay-4" style="z-index: 1008; display: block; opacity: 0.5;"></div> |
It might be relevant to mention that previous behaviour probably did reuse the overlay, as if you opened 2 different modals and then closed 1 one of them it would remove all the overlay completely and you would end up with the other modal still present in the page without the dark overlay. |
Couldn't each modal have it's own overlay reference and reuse it when it is opened a second time? However, this would have the (probably already existing) side-effect of having a darker overlay when opening 2 different modals at the same time. |
Yeah, I think we need to be able to easy track the number of overlays opened and the cleanest way could probably be to add a The current modal add overlay code can be see in the leanModal.js - L23-61 file. As you have shown, the code will add a new In essence having something like:
The main reason I suggest to add the counter as an attribute is because then other components (like the side menus, date pickers, or whatever) can just reuse the same component. Otherwise the variable _lastID could be replaced to an internal overlay counter. |
Or the since the current code edits the modal |
The problem i see with this implementation is the following:
We need a way to distinguish opening the modal when it is already opened and opening it when its closed IMO. |
Check my last message. I would submit a pull request for that quick fix, but I do not have any of the build requirements to test it, so I hope somebody else could try to implement that. |
You are totally right. I will try to make a pull request for this tonight. |
Do we really want to be able to open an already opened modal? If it is not the case, we could simply check if the modal is already opened at the beginning and return if it is. Please tell me what you think about this. |
Check how the z-index is calculated, if you have multiple modals opened and try to reopen one that is a level below, then z-index still needs to be recalculated. |
hey @pascal-de-ladurantaye, were you able to make any progress on this? |
For the first time in years, I didn't have time to touch my computer for a full weekend 0_o |
@carlosperate I did not test with bottom-sheet modals but I assume it will react the same. |
Looking forward to seeing this fix in the next release. 👍 |
It takes time to go through PR to check code quality and whether or not
|
This issue still persist. When are we getting a fix. |
I am not not sure whether this issue is specific to meteor. But below is a simple fix I did: $('.modal-trigger').leanModal( |
I actually submitted a pull request on Jun 25. But no response at all. I have just merged latest master branch and hopefully this time someone would look at it. Anyway I still implement the code in my project to fix the issue. If you guys have some issue you can simple use my code. #1590 Copy the code and use grunt to recompile the materialize.js and materialize.min.js. |
Is this issue solved? Also, how to set dimissable without calling a closeModal() or openModal() actions? Suppose you want to block a modal for a call to action. Then, I simply would like to click on the lean-modal background, but it stays blocked. I tried to override dimissable click on the layer but it did not work. $modal = $('#modal-call-action'),
$overlay = $('<div class="lean-overlay"></div>'),
$overlay.click(function() {
$modal.closeModal({dismissible : true, complete: function() { $('.lean-overlay').remove() }});
}); I currently overrided it like:
but something cleaner would be better. Also, could you explain the difference for calling The first return me one object only; the latter the array of all overlapping lean-overlays div. Thank you! |
confirming that @alexofob's workaround of adding the following to initialisation works.
look forward to this not being necessary. |
This has been fixed for over 8 months.... If only they merged the PR. Pascal de Ladurantaye On Thu, Jan 21, 2016 at 11:41 AM, Bobbie Stump notifications@github.com
|
I had to do a LOT more than "remove lean-overlay". Looks like it's an issue when you use a jQuery multi-selector and/or when you add content to the modal through AJAX. I have attached a file with the fix. |
@pascal-de-ladurantaye I just grabbed leanModal.js from the master repo and it's still broken. My zip file above fixes it. What branch is this issue resolved in? |
Why has this not been merged? Adding the removal of lean-overlay to |
While I do agree this should have been fixed a while ago it's not as simple as just removing the overlay. You can have multiple modals opened, each overlaying the previous modal, what happens then when you reopen a modal that was hidden behind a newer one? Also, if you close any of those, only it's relevant overlay should be removed and the rest left behind. All that said, this behaviour has been taken in consideration and fixed in #1691 ... |
Ah yes, wasn't aware of those complications. At any rate, cheers, I see #1691 is due to be merged imminently. |
To anyone who wants to solve this problem by using my code and recompiling the package. please checkout the file https://github.com/JonathanGuo/materialize/blob/Fixed-duplicated-leanModal-overlays/js/leanModal.js I created a pull request #1590 ages ago and never been merged. This piece of code perfectly solved this issue. We already used this in our product. I am not going to resubmit my code and hope the code to be merged. |
@JonathanGuo could you please help me understand how I could apply your fix? I'm using the materialize:materialize package on meteor, and I can't find the leanModal.js file anywhere. Do I have to remove the package, download the materialize, and your file, and add it back? That might cause other packages which have dependency on materialize to break. 😢 |
Honestly though, I do wish this issue was closed if the pull request is valid! |
@samudranb I know it's a pain. So in our project I folked the Materializecss and applied the changes. Then I have my own gruntfile.js to build the js file. In this way there is no conflict but every time you update the Materializecss package, you need to run your own gruntfile.js to generate the file. For your gruntfile, you can simply copy https://github.com/Dogfalo/materialize/blob/master/Gruntfile.js and change the leanModel.js route to yours. |
Thanks @JonathanGuo ! I'll check it out |
hi ! i found a solution for me maybe it's work for you :
|
Hi there, I thought I would just add my fix that I placed in materialize.js within the openModal extension. If there is more than 2 layers, it will just delete them, its not the most efficient method but it seems to operate better for me than the fix to leanModal.js.
|
So what happens if you have one modal opened, and then a different one opens on top? |
It only ever has two overlays max. 0 and 1 in the .each statement. If there was a 3rd one I would bump it up to 2. However I think it may struggle if there were anymore than 2. It seems to work better than the leanModal fix for the time being. (well atleast for my implementation) The lean modal fix was buggy as, and for some weird reason was shutting down my modals and overlays for no reason that I could see. The above needs to be in a function that operates everytime a modal opens. (or if you prefer every second modal). I did forget to mention you still need:
However when it comes to duplicate overlays appearing, my code helps prevent the background from going all black by removing the "too many" overlays factor. So if you are getting duplicate overlays use my code above, and to remove the overlays use the above. It looks way smoother. |
Above patches doesn't fix for me.
So, opening and closing recursively modals, it remembers the last ".lean-overlay" ID and then uses another new one. This cause the issue! $('.modal-trigger').leanModal({
dismissible: true,
opacity: 0.5,
in_duration: 300,
out_duration: 200,
ready: function() {
if($(".lean-overlay").length > 1) {
$(".lean-overlay:not(:first)").each(function() {
$(this).remove();
});
}
},
complete: function() {
$(".lean-overlay").each(function() {
$(this).remove();
});
}
}); |
Try this one guys, |
Not sure if this is the same problem I was having (sounds the same). I resolved by using unbind() before calling. |
@gubi's example did the trick for me (thanks!). Hope they will patch this at some point tho. |
@Dogfalo @acburst Are you still actively maintaing your awesome library? Thoughts? @pascal-de-ladurantaye ? |
@Dogfalo What's the status with this issue? |
@gdoron The PR was merged. And here something about the state of this project |
@tomscholz Indeed it is, glad traction is starting to take place :)... with 25k+ stars that's a pretty important library to lots of people. Lets keep it that way. |
Closed due inactivity and being solved. |
So if a modal is opened multiple times, and then exited only the latest overlay is removed and all other stay there permanently.
To test you can go to http://materializecss.com/modals.html and in the javascript console just run
$('#modal1').openModal();
multiple times. You can see that after clicking any of the modal options only one overlay is removed.The text was updated successfully, but these errors were encountered: