fix(useKeyPress): cannot listen to modifier key keyup events with exactMatch#2944
Open
Muhamed-Ragab wants to merge 1 commit into
Open
fix(useKeyPress): cannot listen to modifier key keyup events with exactMatch#2944Muhamed-Ragab wants to merge 1 commit into
Muhamed-Ragab wants to merge 1 commit into
Conversation
- Add event.type === 'keyup' check in modifierKey.shift, .ctrl, .alt following the existing pattern for meta - On keyup: use event.keyCode to detect the modifier key - On keydown: use event.shiftKey, event.ctrlKey, event.altKey (unchanged) close alibaba#2704
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
useKeyPress('shift', handler, { events: ['keyup'], exactMatch: true }) does not fire because event.shiftKey is false on keyup (the key is already released).
Root Cause
The modifierKey.shift, .ctrl, and .alt handlers check event.shiftKey, event.ctrlKey, event.altKey which are false on keyup. While modifierKey.meta already had special handling for keyup (checking event.keyCode instead), the other modifiers did not.
Changes
packages/hooks/src/useKeyPress/index.ts
packages/hooks/src/useKeyPress/tests/index.spec.tsx
Verification
Related
Closes #2704