question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Prevent dismissing when clicking in certain element outside

See original GitHub issue

When 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. Animation (2)

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:11

github_iconTop GitHub Comments

1reaction
horntacommented, Nov 29, 2022

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

0reactions
atomikscommented, Nov 29, 2022

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 FloatingTrees

Of course in the meantime the FloatingOverlay thing should work fine like this:

<FloatingOverlay 
  onClick={event => event.target === event.currentTarget && setOpen(false)}
>
  <Dialog />
</FloatingOverlay>

Edit: although, it doesn’t handle not closing when pressing the scrollbar

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found