mantine icon indicating copy to clipboard operation
mantine copied to clipboard

Hotkey digits not working

Open AykutSarac opened this issue 7 months ago • 8 comments

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

AykutSarac avatar May 06 '25 07:05 AykutSarac

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.

Han5991 avatar May 06 '25 11:05 Han5991

Thanks for the clarification!

AykutSarac avatar May 06 '25 16:05 AykutSarac

This doesn't work on Windows for us. Can we repoen?

cortfritz avatar May 06 '25 16:05 cortfritz

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.

sch avatar May 06 '25 17:05 sch

I don't think intercepting from the system can be done in the library. I'm curious about your thoughts.

@rtivital

Han5991 avatar May 07 '25 00:05 Han5991

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 avatar May 08 '25 07:05 rtivital

@rtivital can i fix it?

scato3 avatar May 15 '25 02:05 scato3

Sure

rtivital avatar May 15 '25 04:05 rtivital

@rtivital I'm on Windows and it outputs normally in Storybook.

Image

scato3 avatar Jun 19 '25 01:06 scato3