-
Notifications
You must be signed in to change notification settings - Fork 11
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
Not working in different instances of the component. #16
Comments
Hi @davidmoreno92 , thanks for calling this out. I haven't had much time to devote to this package lately, but if you or anyone else is willing to find a fix, I'll happily review it and merge it if it works! |
I will try if i have time mate. Thanks. |
This happens because only a single click listener is actually added to the DOM, or something like that. There is a single ref object with different trigger functions: const citySelectorRef = useDetectClickOutside({
onTriggered:
focusedField === 'ORIGIN'
? handleOriginInputBlur
: handleDestinationInputBlur
}); And in the JSX the ref is defined accordingly: ref={focusedField === 'ORIGIN' ? citySelectorRef : undefined} Update: I found a problem with this approach. |
I cannot reproduce this problem at all. I think it works fine for multiple instances of same component. I created a CodeSandbox demo here: https://codesandbox.io/s/brave-pare-1j8xsm?file=/src/App.tsx There you can see that two boxes behave correctly:
|
Hi, first of all, thanks for this package. It works great.
I encountered a problem while trying to implement two instances of the same component with the "useDetectClickOutside" approach.
It is not working in the second instance, it just triggers close when clicking and closes all.
I tried by adding unique key in each component instance, but it keeps failing.
Thanks.
The text was updated successfully, but these errors were encountered: