JohannesKlauss / react-hotkeys-hook

React hook for using keyboard shortcuts in components.
https://react-hotkeys-hook.vercel.app/
MIT License
2.56k stars 112 forks source link

[BUG] `mod` modifier listens to `ctrl` on macOS #1181

Closed ItaiYosephi closed 1 week ago

ItaiYosephi commented 1 month ago

Describe the bug mod should only listen to meta, but on macOS, it also listens to ctrl.

To Reproduce Steps to reproduce the behavior:

  1. using macOS, press ctrl+k in the following stackblitz demo

Link to reproducable

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

terryttsai commented 1 week ago

+1, I am seeing the same issue

JohannesKlauss commented 1 week ago

This is not a bug, but standard behavior and mentioned in the docs. If you want to listen to meta, then you have to listen to meta and not mod. mod will capture both modifier keys. This is the browsers behavior

terryttsai commented 6 days ago

Maybe can update the documentation to make that more clear then?

"mod (which listens for ctrl on Windows/Linux and cmd on macOS)"

could be

"mod (which listens for ctrl on Windows/Linux and either ctrl or cmd on macOS)"

ItaiYosephi commented 6 days ago

@JohannesKlauss as @terryttsai commented, from the docs its seems that mod shuld only correspond to cmd on macOS... Maybe we can reopen this as a feature request? To add a new modifier that will correspond to ctrl on Windows and cmd on macOS? Currently there is now way to achieve it, but it seems like a pretty common use case . For example, on macOS , only cmd+k opens a command menu on GitHub/Linear/Jira (ctrl+k opens the menu on Windows but not on macOS).

terryttsai commented 6 days ago

As a workaround, I'm using react-device-detect and setting meta for macOS and ctrl for Windows:

import { isMacOs } from 'react-device-detect';

export const MOD_KEY = isMacOs ? 'meta' : 'ctrl';

But it would be nice if we can add a modifier that just corresponds to cmd on macOS and ctrl in Windows/Linux