react-detect-click-outside icon indicating copy to clipboard operation
react-detect-click-outside copied to clipboard

stopPropagation() not working

Open sneridagh opened this issue 4 years ago • 3 comments

Hi! I have an edge case, where I click from a mounted element that immediately gets unmounted, then the listener handler can't see it "contained" inside the reference object, then it catches it as a "click outside". I tried to use a stopPropagation() but I stumbled upon the same limitation explained in this post:

https://dev.to/dvnrsn/why-isn-t-event-stoppropagation-working-1bnm

so the React synthetic events are attached to window, not to document, then the stopPropagation does not work :(

I already tried it out and attaching the listener to window instead of document works fine. Do you think it's worth to add it to the library? (maybe even as an option?) I can make a PR.

sneridagh avatar Apr 16 '21 09:04 sneridagh

Ok it seems there is a workaround to the issue, writing it here for further reference:

https://stackoverflow.com/questions/24415631/reactjs-syntheticevent-stoppropagation-only-works-with-react-events/52879137#52879137

https://gist.github.com/ggregoire/ce7bc946212920c0a6bad8125567d001

sneridagh avatar Apr 17 '21 08:04 sneridagh

@sneridagh Thanks for bringing this edge case to my attention - any chance you could post a sandbox link with a simple version of the issue you're facing (with or without the solution you linked)?

zhaluza avatar Apr 18 '21 14:04 zhaluza

@zhaluza I am facing also stopPropagation() problem so i had to add this and the package works then fine. I think this issue is happening with React 18 version. Please check this problem. Again after installing the package it was not working properly that supposed do, but when I add stopPropagation() then works fine. Thanks.

hasanulhaquebanna avatar May 13 '22 21:05 hasanulhaquebanna