Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Triggers while focussed on input field since v3.0.0 #438

Closed
laurensnl opened this issue Dec 24, 2020 · 14 comments
Closed

Triggers while focussed on input field since v3.0.0 #438

laurensnl opened this issue Dec 24, 2020 · 14 comments

Comments

@laurensnl
Copy link

Since updating to v3.0.0, the hotkeys also trigger while entering text in an input field.

I use the hook like this:

useHotkeys('d', () => toggle());
velut added a commit to jsdocs-io/web that referenced this issue Dec 24, 2020
Fixes not being able to use hotkey 's' as a letter in the search input.

See JohannesKlauss/react-hotkeys-hook#438
@JohannesKlauss
Copy link
Owner

JohannesKlauss commented Dec 27, 2020

Weird, I'll look into it. Thanks for raising the issue.

@JohannesKlauss
Copy link
Owner

Fixed in 3.0.1

@richardsolomou
Copy link

@JohannesKlauss This seems to still be affecting elements with contenteditable

@laurensnl
Copy link
Author

laurensnl commented Dec 29, 2020

After the update to v3.0.1, I get this error when pressing a hotkey while focussed on an input field:

Cannot read property 'enableOnTags' of undefined

Screenshot 2020-12-29 at 12 53 08

@houmark
Copy link

houmark commented Dec 30, 2020

I can confirm getting the same error as @laurensnl

@JohannesKlauss
Copy link
Owner

I am sorry, I'll look into it. Shouldn't create a major update before the holidays, haha.

@JohannesKlauss
Copy link
Owner

Should be fixed with 3.0.2

@laurensnl
Copy link
Author

The good news is that the error is gone. The bad news is that letters that are assigned to an hotkey cannot be entered in input fields anymore.

Example
I have assigned the 'd' key as an hotkey:

useHotkeys('d', () => toggleDarkMode());

When I'm typing in a text field, I can not enter a 'd'.

@JohannesKlauss
Copy link
Owner

Fixed with 3.0.3

@laurensnl
Copy link
Author

Thanks @JohannesKlauss! I can confirm that everything works as expected now. 🎉

@richardsolomou
Copy link

@JohannesKlauss This is still affecting elements with contenteditable

@JohannesKlauss
Copy link
Owner

@richardsolomou I'll try to have a look at it over the weekend.

@rvrheenen
Copy link

rvrheenen commented Mar 24, 2021

@JohannesKlauss This is still affecting elements with contenteditable

I had the same problem, and I found a workaround for in the meantime:

const useHotkeyPreventer = (ref) => {
  if (ref.current) {
    ref.current.onKeyDown = (event) => {
      event.stopPropagation();
    };
  }
};

const ref = useRef(null);
useHotkeyPreventer(ref);

and in the rendering part:

<ComponentThatIsEditable contentEditable="true" ref={ref} />

@JohannesKlauss
Copy link
Owner

JohannesKlauss commented Mar 29, 2021

@richardsolomou Finally fixed this behavior in the 3.3.0 version.
If a target element has its contentEditable attribute set to true, hotkeys won't trigger.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants