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
Can't use keydown on components which use portals #68
Comments
I may be wrong, but looking at your code here, it seems to me if you decorate your I don't know how
Let me know if it makes sense |
Thank's for your reply :). That sounds reasonable and could work. I'll try it tomorrow. Nevertheless it would be great to also be able to use react-keydown on components which use portals. The expected behavior in my opinion would be, that the methods in the component receive all keydown events of the window. |
Appreciate the feedback. However, IMHO I don't think that's the purpose of WDYT @glortho |
i agree that @salmanm's suggestion above should work: #68 (comment) i also agree about global event binding. one of the main inspirations/use-cases of react-keydown is shifting scopes. for example, you may want to use navigational arrow keys to navigate lots of different lists/grids in your app. setting up global bindings for that can get complex quickly. react-keydown tries to make an educated guess at which context should get dibs on otherwise duplicate keybindings based on where the user appears to have been most active most recently. if you really do want global keybindings that are active all the time, you can indeed set up your own bindings with |
@salmanm @glortho. The solution in #68 (comment) works perfectly. Thank you. I really appreciate your work and really like react-keydown. Do you think it's not suitable for the library to include some kind of mechanism to listen to all keydowns of the window. Maybe including an additional decorator |
that's not a bad idea @mmsbrggr . what do you think @salmanm ? it's starting to seem like we need to accept options. then again, you don't really want |
Hmmm if it is to avoid binding and unbinding in Also, finding conflicting keybindings could be tricky. So I think if we just keep it stupid simple and call all handlers registered as global bindings that could work. |
Hey :)
I have a modal component which renders some markup in a portal (so it overlays the whole body). I wanted to use
react-keydown
to close the overlay when the ESC key is pressed. This is not working. I believe that the problem is thatreact-keydown
only listens on keydowns which happen inside the component. Through react-portal the overlay jumps out of the current component. What would be needed is to somehow listen to all keydowns of the whole window.The text was updated successfully, but these errors were encountered: