Skip to content

fix(useKeyPress): cannot listen to modifier key keyup events with exactMatch#2944

Open
Muhamed-Ragab wants to merge 1 commit into
alibaba:masterfrom
Muhamed-Ragab:fix/issue-2704
Open

fix(useKeyPress): cannot listen to modifier key keyup events with exactMatch#2944
Muhamed-Ragab wants to merge 1 commit into
alibaba:masterfrom
Muhamed-Ragab:fix/issue-2704

Conversation

@Muhamed-Ragab

Copy link
Copy Markdown

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

  • Added event.type === 'keyup' check to modifierKey.shift, .ctrl, .alt (following the existing pattern for meta)
  • On keyup: check event.keyCode === 16/17/18 to detect the modifier key
  • On keydown: use event.shiftKey/event.ctrlKey/event.altKey (unchanged)

packages/hooks/src/useKeyPress/tests/index.spec.tsx

  • Added 4 tests: shift/ctrl/alt keyup with exactMatch + combination keys regression guard

Verification

  • All 14 tests pass (10 existing + 4 new)

Related

Closes #2704

Submitted by Cursor

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

CLAassistant commented Jun 12, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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.

[useKeyPress] can't listen shift keyup

2 participants