Skip to content

fix: add event.code fallback for Alt+punctuation keys on macOS#64

Open
danyi1212 wants to merge 1 commit intoTanStack:mainfrom
danyi1212:feat-fix-alt-punctuation-macos
Open

fix: add event.code fallback for Alt+punctuation keys on macOS#64
danyi1212 wants to merge 1 commit intoTanStack:mainfrom
danyi1212:feat-fix-alt-punctuation-macos

Conversation

@danyi1212
Copy link

@danyi1212 danyi1212 commented Mar 12, 2026

Summary

  • On macOS, the Option (Alt) key acts as a character composer for punctuation keys (e.g., Option+- produces an en-dash ), causing event.key to differ from the expected character. This prevented Alt+punctuation hotkeys like Alt+-, Alt+/, Alt+[, etc. from matching.
  • Added a PUNCTUATION_CODE_MAP in constants.ts that maps event.code values (Minus, Equal, Slash, BracketLeft, BracketRight, Backslash, Comma, Period, Backquote, Semicolon) to their canonical characters, following the same fallback pattern already used for letter (Key*) and digit (Digit*) codes.
  • This also fixes dead-key + punctuation code matching (e.g., Alt+[ when event.key is Dead).

Fixes the issue described in the bug report where all PUNCTUATION_KEYS combined with Alt on macOS failed to match.

Test plan

  • Added tests for all punctuation keys with Alt modifier (Alt+-, Alt+=, Alt+/, Alt+[, Alt+], Alt+\, Alt+,, Alt+., `Alt+``)
  • Added test for multi-modifier combinations (Mod+Alt+- on macOS)
  • Added test for direct punctuation matching without fallback (no regression)
  • Added test for missing event.code edge case
  • Added test for dead key + punctuation code fallback
  • Updated existing dead-key test to expect correct behavior
  • pnpm test passes (all targets: eslint, types, lib, docs, build)

On macOS, the Option (Alt) key acts as a character composer for
punctuation keys (e.g., Option+- → en-dash '–'), causing event.key
to differ from the expected character. This prevented Alt+punctuation
hotkeys from matching.

Add a PUNCTUATION_CODE_MAP that maps event.code values (Minus, Equal,
Slash, BracketLeft, etc.) back to their canonical characters, following
the same fallback pattern already used for letter (Key*) and digit
(Digit*) codes.
@changeset-bot
Copy link

changeset-bot bot commented Mar 12, 2026

🦋 Changeset detected

Latest commit: 588eb03

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 12 packages
Name Type
@tanstack/hotkeys Patch
@tanstack/angular-hotkeys Patch
@tanstack/hotkeys-devtools Patch
@tanstack/preact-hotkeys Patch
@tanstack/react-hotkeys Patch
@tanstack/solid-hotkeys Patch
@tanstack/svelte-hotkeys Patch
@tanstack/vue-hotkeys Patch
@tanstack/preact-hotkeys-devtools Patch
@tanstack/react-hotkeys-devtools Patch
@tanstack/solid-hotkeys-devtools Patch
@tanstack/vue-hotkeys-devtools Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

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.

1 participant