react-hotkeys-hook
react-hotkeys-hook copied to clipboard
[BUG] 'meta/shift/alt+-' is not working
Describe the bug
Modifiers like meta/shift/alt combined with '-' is not working, but ctrl+- does.
To Reproduce Steps to reproduce the behavior:
- Go to the official website
- Edit one of those code examples to
meta+- - Press
meta+- - Nothing happened
It is the same with my real project.
Please try and add a codesandbox or stackblitz to reproduce the bug: <-- Link to reproducable -->
Expected behavior
meta/shift/alt+- working as expected.
Screenshots If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
- macOS 12.6.3
- Chrome 110.0.5481.177
Cannot reproduce that on the webpage. Events are triggering fine. Please add an isolated reproducible.
Mind you, that after editing the code on the website you have to refocus the Live Editors output in order to make the hotkeys work, since they are all scoped to that output.
Thanks for the reply, here is a codesandbox reproduction link: https://codesandbox.io/p/sandbox/musing-christian-ys7uoc
I'm also facing an issue where meta+, doesn't work
@javoski I am still not able to reproduce this, works absolutely fine for me on Chrome and mac. I am on macOS 11 though, so I'll update to 12. But still, are you sure that there aren't any custom system key mappings that filter out that event? What's the console output on this sandbox if you hit the meta+- for example? https://codesandbox.io/s/react-hotkeys-template-bzvk53
@timnlupo Did you set the splitKey option to something else? , defines a combination split by default. In order to use it as part of a key combination you have to set the splitKey option to a different key.
What's the console output on this sandbox if you hit the
meta+-for example? https://codesandbox.io/s/react-hotkeys-template-bzvk53
Nothing happened but the web page zoom-out.
FYI, it's working when I use meta+minus instead.
I had the exact same issue. meta+minus works for me too. Using macOS 13.2.1
I'm also facing an issue where
meta+,doesn't work
This doesn't work for me either. I've confirmed it works still with v4.3.5/6/7 but v4.3.8 it does not. Codesandbox
Actually changing the splitKey does get around the issue:
useHotkeys(
["Meta+Shift+,"],
() => {
setCount(count + 1);
},
{ splitKey: "-" } // change this to something else and it works
);
A decent workaround for the moment.
EDIT: I guess you could argue this isn't a bug to begin with, it's certainly a collision of a hotkey definition. But since there is an override option already available I wonder if there somehow just needs some clarification regarding the choice of key combinations.
With v4.4.0, I seem to be seeing this issue as well with both shift+plus and shift+= even without using meta.
The work around above did not work in this case.
I encountered the same issue, wanting to add a hotkey on shift+plus and tried everything (plus, +, changing the splitKey, etc.). Ultimately, a look at the code gave me a working - albeit strange - solution:
https://github.com/JohannesKlauss/react-hotkeys-hook/blob/92bb90e7eb61962cf0eadcbd068f849652e39fd3/src/parseHotkeys.ts#L14
useHotkeys("shift+bracketright", () => { alert("'shift +' was pressed") });
looks like that solution works for shift, but not for the meta key .
The following doesn't seem to work for me:
useHotkeys("meta+bracketright", () => { alert("'meta +' was pressed") });
Is there a plan to fix this bad mapping? using bracketright for plus works, but also adds a hotkey on the ] key
Note that the shift+bracketright for "shift +" worked until version 4.4.1, but stopped working in 4.4.4 and 4.5.0