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

[BUG] hotKeys trigger from input inside WebComponent #1161

Open
HJK181 opened this issue Apr 4, 2024 · 2 comments
Open

[BUG] hotKeys trigger from input inside WebComponent #1161

HJK181 opened this issue Apr 4, 2024 · 2 comments

Comments

@HJK181
Copy link

HJK181 commented Apr 4, 2024

Describe the bug
Hotkeys triggers if users has focus on an input inside a WebComponent. This is because events that happen in shadow DOM have the host element as the target, when caught outside of the component, see: https://javascript.info/shadow-dom-events

To Reproduce
Steps to reproduce the behavior:

  1. Render a WebComponent input inside your React component, e.g. https://www.webcomponents.org/element/@polymer/paper-input
  2. Use the useHotkeys with some keys
  3. Focus the WebComponent input and press a key triggering the hotKey

Please try and add a codesandbox reproduce the bug:

just press c while focus is inside the input.

Expected behavior
The hotkey is not triggered if the focus element is one of the elements the hook already takes care of when used inside a WebComponent. To solve this, isHotkeyEnabledOnTag should not just use _ref.target but also check if the _ref.composedPath()[0].tagName if the composed property of the event is true, indicating that the event is a composed event that can pass through shadow DOM boundaries, including events from within web components.

@HJK181
Copy link
Author

HJK181 commented Apr 9, 2024

I gave it a try: #1164

@JohannesKlauss
Copy link
Owner

Thank you for your work, I'll have a look at it.

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

2 participants