-
Notifications
You must be signed in to change notification settings - Fork 119
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
ref
returned from useHotkeys
does not work on conditionally rendered elements
#1198
Comments
yeah that ref in general doesn't work well. That bug above is pretty nasty as it locks out the whole page, forever. Also If you hit the shortcut like CTRL+C from an unrelated element and shortly after do it again on the element with the ref, yoU get 2 function calls instead of one, even if the second keyboard keypress is CTRL alone. Mega buggy. |
I ran into this as-well - was very annoying to figure out. But luckily I was able to just move the ref to the parent element, although some may be in a different position. That seemed to fix everything The symptoms were that I had some other inputs on the page that I realized I couldn't type into on the initial render of the conditional element that had the ref attached to it. Clicking off the page after initial render and coming back fixed it. But made for a couple hour debugging session on what was wrong. |
Should be fixed by #1132 |
Yes, this was released in 4.5.1 just now. |
Is your feature request related to a problem? Please describe.
It took me a lot of frustration to realize that using
ref
returned fromuseHotkeys
on conditionally rendered element which is initially absent results in weird (and possibly unintended) behavior:keydown
event listener will be added on thedocument
.ref
will update.document
but behave like it is added on the element.As a result all
keydown
events will bestopPropagation
ed andpreventDefault
ed when the focus is outside the element. Among other things, Tab navigation stops working, which is an accessibility concern.Describe the solution you'd like
Some way to pass additional dependencies for
useLayoutEffect
inside theuseHotkeys
hook, e.g. throughoptions
object.Describe alternatives you've considered
useCallback
to theuseLayoutEffect
as well.ref
fromuseHotkeys
does not support conditionally rendered elements as it breaks accessibility and potentially other hotkeys. This can always be mitigated by wrapping conditionally rendered element in a component.The text was updated successfully, but these errors were encountered: