github / hotkey

Trigger an action on an element with a keyboard shortcut.
https://github.github.com/hotkey/
MIT License
3.22k stars 97 forks source link

Listen for some hotkeys on form fields #28

Closed tobyzerner closed 4 years ago

tobyzerner commented 4 years ago

Thanks for the great lib!

Currently in the keyDownHandler I see this:

if (event.target instanceof Node && isFormField(event.target)) return

In my use-case I would like to attach an "Escape" hotkey to a cancel button, and a "Command+Enter" hotkey to a submit button, and have these hotkeys be active whilst the focus is in an input/textarea. The above line prevents this.

Understandable that single character and Shift+* hotkeys shouldn't be active, but what about everything else? What's the recommended approach here?

keithamus commented 4 years ago

Hey @tobyzerner thanks for the issue!

This library explicitly ignores shortcuts fired in form fields because it can be very problematic with regard to accessibility.

If you need to enable those kind of shortcuts, it's recommended to bind an event listener directly to handle that specific use case. We do this at GitHub; hotkey is used as a convenience layer but cases that need more fine tuning are done manually.

SethHorsley commented 1 year ago

Hey @tobyzerner thanks for the issue!

This library explicitly ignores shortcuts fired in form fields because it can be very problematic with regard to accessibility.

If you need to enable those kind of shortcuts, it's recommended to bind an event listener directly to handle that specific use case. We do this at GitHub; hotkey is used as a convenience layer but cases that need more fine tuning are done manually.

@keithamus How is this done with the command palette in github and listening to meta+k on all inputs across github?

keithamus commented 1 year ago

https://github.com/github/hotkey/discussions/85