greena13 / react-hotkeys

Declarative hotkey and focus area management for React
https://github.com/greena13/react-hotkeys
ISC License
2.15k stars 160 forks source link

Add "mod" as a key binding like mousetrap #295

Open blainelewis1 opened 3 years ago

blainelewis1 commented 3 years ago

Is your feature request related to a problem? Please describe.

Mousetrap supports mod for command and ctrl being different for mac and windows, but as far as I can tell react-hotkeys does not support that

Describe the solution you'd like

Support mod in the same way that mousetrap does

Describe alternatives you've considered

Could implement in my own code but it ends up spread everywhere

Additional context

I figured out all of the implementation and testing but am waiting for this project to be active to write a pull request.

Basically we take this line

https://github.com/ccampbell/mousetrap/blob/2f9a476ba6158ba69763e4fcf914966cc72ef433/mousetrap.js#L135

'mod': /Mac|iPod|iPhone|iPad/.test(navigator.platform) ? 'meta' : 'ctrl'

And add it to https://github.com/greena13/react-hotkeys/blob/master/src/const/MousetrapToReactKeyNamesDictionary.js

And then write a test where we mock navigator in https://github.com/greena13/react-hotkeys/blob/01cd3747e6949192e53250732c8bb721c5e69d73/test/HotKeys/focus-only/KeyMappings.spec.js