-
Notifications
You must be signed in to change notification settings - Fork 231
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 for dismissible option breaking with multiple popovers open #250
base: master
Are you sure you want to change the base?
Conversation
@@ -78,7 +78,6 @@ | |||
var _srcElements = []; | |||
var backdrop = $('<div class="webui-popover-backdrop"></div>'); | |||
var _globalIdSeed = 0; | |||
var _isBodyEventHandled = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This global setting was preventing the bodyClickHandler from being able to bind multiple times. It would only allow one bind. We want as many binds as there are popovers to happen.
@@ -727,19 +726,18 @@ | |||
}, | |||
|
|||
bindBodyEvents: function() { | |||
if (_isBodyEventHandled) { | |||
return; | |||
} | |||
if (this.options.dismissible && this.getTrigger() === 'click') { | |||
if (isMobile) { | |||
$document.off('touchstart.webui-popover').on('touchstart.webui-popover', $.proxy(this.bodyTouchStartHandler, this)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't tested on mobile, but if we like the separation this provides in the lines below, we could add a unique id here as well.
sandywalker#250 Samuel Brodkey on Sep 6, 2017
I've been working on an app where many popovers are present, using a mix of multi:true and dismissible:false and have run into issues where the dismissible option seems to not be functioning correctly.
Problem: Opening a dismissible popover along with a non-dimissible popover can cause the non-dismissible popover to become dismissible! This is because when we have the non-dismissible popover open and click outside of it, the "bodyClickHandler" runs for the dismissible popover and calls hideAllPop() inside of it! We would prefer that it only calls this.hide() to only hide itself, not other non-dismissible popovers.
So, we have now made it so popovers can only dismiss themselves. I think this makes sense as a dismissible popover should not be able to tell a non-dismissible popover to close (unless multi:false).
However, this reveals a pre-existing issue in that not all bodyClickHandlers are running for every popover. If we click outside of two dismissible popovers, only one will close, showing that not all are running. This is because "click.webui-popover" is not a unique event. To make it unique, we append this._idSeed. Now, each popover has its own bodyClickHandler in which it can close itself if the right conditions occur.
Please see demo/test-issue248.html which I've created and make sure we're running the version of web-uipopover before these changes! It will walk you through these issues and demonstrate why these fixes are necessary.