github/hotkey

Listen for some hotkeys on form fields

Closed this issue · 3 comments

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?

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.

iseth commented

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?