Skip to content

fix: handle dead keys in matchesKeyboardEvent#40

Merged
KevinVandy merged 6 commits intoTanStack:mainfrom
ntilwalli:fix-dead-key-fallback
Mar 3, 2026
Merged

fix: handle dead keys in matchesKeyboardEvent#40
KevinVandy merged 6 commits intoTanStack:mainfrom
ntilwalli:fix-dead-key-fallback

Conversation

@ntilwalli
Copy link
Contributor

🎯 Changes

When event.key is 'Dead' (length 4), the existing event.code fallback—gated behind eventKey.length === 1—was never reached, causing hotkeys to silently fail.

This most commonly affects macOS, where Option+letter combinations like Option+E, Option+I, Option+U, and Option+N produce dead keys for accent composition. It also affects Windows and Linux users with international keyboard layouts (e.g., US-International, German, French) where certain key combinations produce dead keys.

Added an early check: when event.key normalizes to 'Dead', immediately fall back to event.code to extract the physical key via the Key*/Digit* prefixes. Punctuation dead keys (e.g., ' on US-International, where event.code is 'Quote') correctly return false since their codes don't match letter or digit patterns.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

When event.key is 'Dead' (length 4), the existing event.code fallback
(gated behind eventKey.length === 1) was never reached, causing hotkeys
to silently fail.

This most commonly affects macOS, where Option+letter combinations like
Option+E, Option+I, Option+U, and Option+N produce dead keys for accent
composition. It also affects Windows and Linux users with international
keyboard layouts (e.g., US-International, German, French) where certain
key combinations produce dead keys.

Adds an early check: when event.key normalizes to 'Dead', immediately
fall back to event.code to extract the physical key via the Key*/Digit*
prefixes. Punctuation dead keys (e.g., apostrophe on US-International,
where event.code is 'Quote') correctly return false since their codes
don't match letter or digit patterns.

Includes 10 tests covering dead key scenarios for letter keys, digit
keys, modifier combinations, mismatches, and missing/invalid codes.

Co-authored-by: Cursor <cursoragent@cursor.com>
@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 24, 2026

Open in StackBlitz

@tanstack/hotkeys

npm i https://pkg.pr.new/@tanstack/hotkeys@40

@tanstack/hotkeys-devtools

npm i https://pkg.pr.new/@tanstack/hotkeys-devtools@40

@tanstack/preact-hotkeys

npm i https://pkg.pr.new/@tanstack/preact-hotkeys@40

@tanstack/preact-hotkeys-devtools

npm i https://pkg.pr.new/@tanstack/preact-hotkeys-devtools@40

@tanstack/react-hotkeys

npm i https://pkg.pr.new/@tanstack/react-hotkeys@40

@tanstack/react-hotkeys-devtools

npm i https://pkg.pr.new/@tanstack/react-hotkeys-devtools@40

@tanstack/solid-hotkeys

npm i https://pkg.pr.new/@tanstack/solid-hotkeys@40

@tanstack/solid-hotkeys-devtools

npm i https://pkg.pr.new/@tanstack/solid-hotkeys-devtools@40

commit: 3987398

}

// For single letters, compare case-insensitively
if (eventKey.length === 1 && hotkeyKey.length === 1) {
Copy link
Member

Choose a reason for hiding this comment

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

there's now some redundant code here. I think it can be refactored a bit. I'll check it out tonight.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, thanks for pointing that out. Fixed.

ntilwalli and others added 4 commits March 1, 2026 21:19
…ar mismatches

Address review feedback by consolidating the dead key handler and the
existing single-character event.code fallback into a single code path.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@KevinVandy KevinVandy merged commit 762cabf into TanStack:main Mar 3, 2026
3 checks passed
@github-actions github-actions bot mentioned this pull request Mar 3, 2026
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.

3 participants