Open zelaznik opened 3 years ago
@zelaznik I don't have that problem in our app. Have you tried wrapping the inner clickable menu area in a stop-propagation
modifier?
Example:
<div>
<button
type="button"
{{on "click" (set this "menuIsOpen" (not this.menuIsOpen))}}
{{on-click-outside
(set this "menuIsOpen" false)
eventType="mousedown"
exceptSelector=(concat "#" this.menuId " *")
}}
>
</button>
{{#if this.menuIsOpen}}
<div
id={{this.menuId}}
{{on "click" (stop-propagation (set this "menuIsOpen" true))}}
>
[some clickable stuff here]
</div>
{{/if}}
</div>
@zelaznik Sorry, got buried by other notifications.
Related: https://github.com/zeppelin/ember-click-outside/issues/49
Will check what could be done in the coming days!
Summary:
I tried add this modifier to a modal in our app. The modal is supposed to close if a user clicks outside the main content region. It's closing the modal when it shouldn't:
This behavior should not be considered an outside click. To check whether this behavior is intentional, try clicking your mouse anywhere on a webpage, dragging your cursor on top of an interactive element such as a button or a link, and then release the cursor. The browser does not behave as though you just clicked on that button.
Possible solution:
Before I knew that this library even existed, I built our own outside click handling for our modal and had to deal with this very problem. It involves adding
mousedown
andmouseover
listeners for the target area, and also addingmousedown
andmouseup
listeners for the entire document. Those events update a state object to track whether the mouse was ever clicked down on the target area or dragged over the target area. If either of those answers is "Yes", it doesn't fire the callback.Here's the code I implemented for a standalone modifier. I tried looking through your source code, but I haven't digested it well enough to feel confident that I could create a PR and not break any of your work.