JohannesKlauss / react-hotkeys-hook

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

[BUG]The keyboard combination doesn't work in focused input #1133

Open Dulatto opened 8 months ago

Dulatto commented 8 months ago

Hello, Please check the code below. What am I doing wrong or missing?

useHotkeys('shift+n', () => console.log('shift + n pressed'), { enableOnTags: ['INPUT'] }); <input type='text' id='fname' name='fname' />

This is part of React component code. If the focus is outside of input the console shows the message, but not if the focus is in input. I need to show the console message when the input is in focus. Thanks.

collinsleewyatt commented 7 months ago

Try putting {enableOnFormTags: true} in the third argument.

Dulatto commented 7 months ago

I tried like: useHotkeys('shift+n', () => console.log('shift + n pressed'), { enableOnTags: ['INPUT'], enableOnFormTags: true });, and still can get console message in any places of screen. I even tried : useHotkeys('shift+n', () => console.log('shift + n pressed'), { enableOnTags: ['INPUT'] }, { enableOnFormTags: true }); to avoid the misunderstanding :)