Skip to content
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

useHotkeys doesn't detect plus key #7123

Closed
1 of 2 tasks
ianparkinson opened this issue Nov 14, 2024 · 3 comments
Closed
1 of 2 tasks

useHotkeys doesn't detect plus key #7123

ianparkinson opened this issue Nov 14, 2024 · 3 comments

Comments

@ianparkinson
Copy link

ianparkinson commented Nov 14, 2024

Dependencies check up

  • I have verified that I use latest version of all @mantine/* packages

What version of @mantine/* packages do you have in package.json?

7.14.0

What package has an issue?

@mantine/hooks

What framework do you use?

Next.js

In which browsers you can reproduce the issue?

Chrome

Describe the bug

useHotkeys from @mantine/hooks doesn't appear to allow binding actions to the + key. Other arithmetical operations (/, *, -) work as expected. In other words, with:

  useHotkeys([
    ['/', handle],
    ['*', handle],
    ['-', handle],
    ['+', handle],
  ]);

...handle gets triggered with any of the /, * or - keys, but not +.

The use-hotkeys documentation links to Key values for keyboard events at MDN, which in turn suggests that the string Add might once have worked, but works no longer in modern browsers. I've also verified that the strings Add, Multply etc. don't work on Chrome 130.0.6723.116.

If possible, include a link to a codesandbox with a minimal reproduction

https://codesandbox.io/p/sandbox/mantine-react-template-forked-zrxnsn

Possible fix

parseHotkey supports strings like alt+j to specify modifiers. It starts with:

  const keys = hotkey
    .toLowerCase()
    .split('+')
    .map((part) => part.trim());

which splits the modifier string up into its individual parts. It goes on to check for modifier names such as alt, shift etc. This unfortunately removes any instances of '+' in the hotkey string. Any fix will presumably involve improving this parsing logic to support +, alt++ etc.

Self-service

  • I would be willing to implement a fix for this issue
@rtivital
Copy link
Member

Fixed with adding this syntax: shift+[plus]. It will be available in 7.14.1 patch.

rtivital added a commit that referenced this issue Nov 16, 2024
@ianparkinson
Copy link
Author

Thank you!

@p-bakker
Copy link

Fixed with adding this syntax: shift+[plus]. It will be available in 7.14.1 patch.

Am wondering a few things about this one:

  • why [plus] and not just plus?
  • seems like in order to support both the + key from the numpad AND the '+' from the regular section of the keyboard (that typically requires pressing the Shift key as well), I now need to register 2 hotkeys?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants