use-keyboard-shortcut icon indicating copy to clipboard operation
use-keyboard-shortcut copied to clipboard

Hook blocks characters used in a combination-shortcut from every input field

Open Bartvaderkin opened this issue 2 years ago • 5 comments

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.

Bartvaderkin avatar May 20 '22 08:05 Bartvaderkin

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.

sergei-maertens avatar May 20 '22 09:05 sergei-maertens

Something like this might work?

https://github.com/arthurtyukayev/use-keyboard-shortcut/compare/develop...at/event-callback

arthurtyukayev avatar Sep 03 '22 23:09 arthurtyukayev

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 avatar Sep 07 '22 01:09 arthurtyukayev

@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']:

  1. If ignoreInputFields is true, the shortcut cannot be triggered while focused on an input, however the letter "U" can be typed. (expected behavior).
  2. If ignoreInputFields is false, the shortcut can be triggered while focused on an input, however the letter "U" can no longer be typed. (bug?)

kndshein avatar Apr 22 '24 02:04 kndshein

I am going to re-open this to investigate.

arthurtyukayev avatar Apr 22 '24 03:04 arthurtyukayev

@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 avatar May 25 '24 20:05 arthurtyukayev

@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.

kndshein avatar Jun 10 '24 22:06 kndshein