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

🐛 Fix #187: Add root prop to HotKeys to allow root HotKeys components… #188

Merged
merged 2 commits into from
Jun 2, 2019

Conversation

greena13
Copy link
Owner

@greena13 greena13 commented Jun 2, 2019

Context

A recent pull request (#186) switched from observing key combination submatches, to ignoring them by default. This revealed there is an issue (#187) with key events being missed by React HotKeys in circumstances where an action is defined with a handler that changes the React DOM or focused element in such a way that the new focused element is outside of any <HotKeys /> descendants, resulting in the corresponding keyup event never being logged - and react-hotkeys behaving as if the key is still held down.

A simple fix for this, is to place a <HotKeys /> component at the top of the react application, so no matter what new content is rendered or what element is focused, it would still be within the descendants of a <HotKeys /> component. However, one react-hotkeys' optimisations is that unless a <HotKeys /> component defines a keyMap prop, it's not actually added to the list of components listening out for key events. This means a user would have to define a keyMap prop of some value (say an empty object), just to get the desired behaviour.

This pull request

Adds a root prop to the <HotKeys /> component, so a user can add such a root <HotKeys /> component, without resorting to a hack to circumvent the intended optimisations in place.

README.md Outdated
@@ -1220,6 +1227,16 @@ Also make sure your React application is not calling `stopPropagation()` on the

Finally, make sure your key event are not coming from one of the [tags ignored by react-hotkeys](#Ignoring-events).

#### React Hotkeys thinks I'm holding down a key I've released

This can happen when you have an action handler that either unmounts the `<HotKeys>` component, or focuses an area of the application where there is no parent `<HotKeys>`. The solution to this is to add a `<HotKeys root>` to the top of your application that renders it as children - or at least high enough to *not* be unmounted or unfocused by your action handler.
Copy link
Owner Author

@greena13 greena13 Jun 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Change parent to ancestor

@greena13 greena13 merged commit 60ae3b9 into master Jun 2, 2019
@greena13 greena13 deleted the bugfix_187 branch June 2, 2019 16:47
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

Successfully merging this pull request may close these issues.

None yet

1 participant