Skip to content
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

False positive if the target element is unmounted by click #11

Open
gpoole opened this issue Dec 3, 2021 · 1 comment
Open

False positive if the target element is unmounted by click #11

gpoole opened this issue Dec 3, 2021 · 1 comment

Comments

@gpoole
Copy link

gpoole commented Dec 3, 2021

In some cases, the hook will call onTriggered unexpectedly if the clicked element removes itself from the DOM via an onClick handler. It seems like by the time useDetectClickOutside's click handler is called, React has already run the target element's onClick, updating and removing the target element from the DOM so it no longer counts as being "inside" the parent.

Here's an example demonstrating the problem:
https://codesandbox.io/s/goofy-shannon-32xh9?file=/src/App.js

@zhaluza
Copy link
Owner

zhaluza commented Dec 4, 2021

Thanks for diagnosing this issue @gpoole ! I may have some time to take a look at this next week, but feel free to put up a PR if you're up to it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants