Prevent dismissing when clicking in certain element outside
See original GitHub issueWhen clicking a floating element I don’t want the click to dismiss the current floating element even though I want it for other clicks. The example shows the problem I’m having where I trigger a notification(that isn’t rendered inside of the current floating element) and clicking on the close button.
I would think I could have a click listener on the useDismiss
options that I could prevent it from being registred as an outside click if I click on something that has a certain data attribute or something.
Clicking on the close button of the alert closes both the alert AND the modal. I don’t want the modal to be closed in this instance.
Issue Analytics
- State:
- Created 10 months ago
- Comments:11
Top Results From Across the Web
JQuery detect click outside element and stop all other click ...
I originally misunderstood that we were trying to stop inline onclick events from firing. I found a potential solution from another ...
Read more >Best practices for handling clicks outside element
Anytime I want to handle the “click outside element” event, I need to make sure I have an additional action that checks the...
Read more >X-On - Alpine.js
x-on can only listen for events with lower case names, as HTML attributes are case-insensitive. Writing x-on:CLICK will listen for an event named...
Read more >Modal - Bootstrap
modal-backdrop to provide a click area for dismissing shown modals when clicking outside the modal. Via data attributes. Activate a modal without writing ......
Read more >How to avoid dropdown menu to close menu items on clicking ...
How to avoid dropdown menu to close menu items on clicking inside ? · Click Inside: · Click Outside: O/P after click outside....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
In their case I believe the modal checks explicitly for clicks on the overlay element so it’s basically ignores clicks on anything, so that’s that, but they do also have a hook for managing what happens when clicking outside an element with a somewhat hard coded escape hatch by checking if the clicked element has a certain attribute or not.
https://github.com/mantinedev/mantine/blob/7e40ca99ad2572dcc416bf2a4417cf38d89e47de/src/mantine-hooks/src/use-click-outside/use-click-outside.ts#L17
It needs to wrap the Notifications component so I think what you’re doing makes sense. Anyways I think I’ll make a PR that adds the function guard option to
outsidePress
and also the ability to specify a custom parent in FloatingTreesOf course in the meantime the
FloatingOverlay
thing should work fine like this:Edit: although, it doesn’t handle not closing when pressing the scrollbar