use-keyboard-shortcut
use-keyboard-shortcut copied to clipboard
Hook blocks characters used in a combination-shortcut from every input field
The key handler eats character keys used in a shortcut even when the modifier is not pressed.
Eg: if I define CTRL+S as shortcut I can't type 's' in any input anymore.
Repro:
- Open a page with this hook and a key combination shortcut, like CTRL+S or CTRL+A, and an input field.
- For example use the online demo from the manual and use your browsers developer inspector to add an input element.
- Try typing in the input field. All characters work except ones used in one of the shortcuts (eg: 'a' or 's' in the demo)
Expected result:
I'd expect the combination shortcuts don't block normal single character input.
Adding to this - the overrideSystem: true
option is set, but can't be set to false
as that triggers the browser save page screen which we want to override.
A possible solution would be to pass the browser event down to the callback handler, so we can invoke event.preventDefault()
as needed.
Something like this might work?
https://github.com/arthurtyukayev/use-keyboard-shortcut/compare/develop...at/event-callback
Fixed in release v1.1.5: https://github.com/arthurtyukayev/use-keyboard-shortcut/releases/tag/v1.1.4
Let me know if you see any further issues.
@arthurtyukayev Looks like this is still the case. Just installed this package for the first time (v1.1.6), and I'm having the same exact issue described here. For instance, I have my shortcut as ['Controll', 'U']
:
- If
ignoreInputFields
istrue
, the shortcut cannot be triggered while focused on an input, however the letter "U" can be typed. (expected behavior). - If
ignoreInputFields
isfalse
, the shortcut can be triggered while focused on an input, however the letter "U" can no longer be typed. (bug?)
I am going to re-open this to investigate.
@kndshein I've reviewed this issue, and it seems like I can only reproduce this issue if I have the overrideSystem
option set to true. Can you make sure you don't have that set to true in addition to have in ignoreInputFields
set to false
?
@arthurtyukayev Thanks for looking into it. I eventually pivoted away from using this package so I can't remember. My hazy memory suggests not using overrideSystem
, which was partially why I chose Ctrl + U
, thinking that I wasn't sure of any existing shortcut w/ that combination. However, I just looked it up and Ctrl + U
is an existing browser shortcut.. so I don't really know. I'm sorry I can't be more helpful.