-
Notifications
You must be signed in to change notification settings - Fork 118
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
Filters seem scoped, but aren't #276
Comments
I'd love to scope it, but i am not sure if this is possible with the underlying hotkeys package. Maybe it's time to think about a custom implementation. But this would take a while |
+1. I ran into this issue and was looking through the code, I can see that |
See comments on JohannesKlauss#276
This fixes the issue of globally scoped filters
I finally have a working dev machine again. I am going through the issues in the next few days. Bare with me. |
So I was thinking about this, but I just don't have the time to come up with a custom all browser compatible solution for a hook based hotkeys package. If anyone else wants to create something like this I'd be glad to support where I can. But for now I just can't make the time. |
I found a fairly easy fix that I implemented in my fork (https://github.com/SteffeyDev/react-hotkeys-hook/blob/feature/scope/src/useHotkeys.ts). Can't PR though cause I made a lot of other changes in my fork that ended up not being good because of how poorly hotkeys-js handles scoping. The idea is that you set the global If someone wants to fork and implement, it should be pretty easy. Unfortunately this would be a breaking change so would probably need a new major version. |
Thank you for sharing, I'll have a look and implement it. |
I implemented a custom filter logic. Basically everything works as before, but the filter is now scoped to each hook instance instead of globally. Since this is a behavioral breaking change, I bumped the major version to |
An example:
You might want to have different filters for different shortcuts. Here, for example, 'Delete' is something you might press during input, so needs to be filtered to ignore input elements, but 'Ctrl+Shift+Delete' is not.
Unfortunately, the hotkey filter functionality is global, so the last filter that's set always wins. In the above example, 'Delete' will fire everywhere, even in input elements, which is not what the author intended.
This isn't very react-y/declarative, as different render orders/rerenderings elsewhere can produce all sorts of strange behaviours here. It'd be better to either scope the filters to the specific shortcut somehow, or to make this behaviour obvious in the useHotkeys API. Setting the filter via
useHotkeys.filter = ...
would make the fact that it's global much clearer, for example.The text was updated successfully, but these errors were encountered: