mantine
mantine copied to clipboard
Hotkey digits not working
Dependencies check up
- [x] I have verified that I use latest version of all @mantine/* packages
What version of @mantine/* packages do you have in package.json?
7.17.16
What package has an issue?
@mantine/hooks
What framework do you use?
Next.js
In which browsers you can reproduce the issue?
None
Describe the bug
Digit[1-9] for hotkey definition are not working since 7.17.6 This commit could be the cause 099b3f51cd82ec0a538b0bebab440fe9c772bd8b
e.g:
useHotkeys([
["shift+Digit1", zoomFit],
["shift+Digit2", focusFirstNode]
])
```js
The issue persists with the latest package, 8.0.0.
### If possible, include a link to a codesandbox with a minimal reproduction
_No response_
### Possible fix
_No response_
### Self-service
- [ ] I would be willing to implement a fix for this issue
To enable physical key matching in the useHotkeys function, you can simply add the usePhysicalKeys: true option when registering the hotkey.
For example:
useHotkeys([
['shift+Digit1', handler, { usePhysicalKeys: true }],
]);
This way, the hotkey will work based on the physical key position (i.e., the Digit key on the keyboard). In this case, the hotkey will be triggered when the event has code: 'Digit1' and shiftKey: true, regardless of the keyboard layout.
If you do not use this option, pressing Shift+1 will be recognized as ! instead of 1, which means the hotkey will not trigger as expected when using shift+Digit1.
Thanks for the clarification!
This doesn't work on Windows for us. Can we repoen?
This codesandbox narrows down the issue: if you set up ctrl + DigitX, shift + DigitX, and ctrl + shift + DigitX, Windows specifically will swallow the ctrl + shift + DigitX case, while MacOS sees three distinct events.
I don't think intercepting from the system can be done in the library. I'm curious about your thoughts.
@rtivital
I've checked it in Chrome on MacOS, it works as intended with this setup:
['shift + Digit1', () => console.log({ message: 'Shift + 1' }), { usePhysicalKeys: true }]
I do not have a working Windows machine, cannot verify and fix the issue on Windows on my side. Help wanted with this issue from someone who works on Windows and can validate and fix the issue.
@rtivital can i fix it?
Sure
@rtivital I'm on Windows and it outputs normally in Storybook.