Skip to content
Source
Sign inSign up
TanStack/hotkeys

feat(hotkeys): Reject unusable hotkeys, return reason codes, and let the top modal dialog take Escape #230

OpenKevinVandywants to merge 5 commits intomain fromfix/reject-unusable-hotkeysopened

Showing 136 changed files with 26 additions and 0 deletions (loading 133).

x
0 of 136 viewed, 136 left
16 additions and 0 deletions.changeset/reason-codes.mdAdded
View file
@@ -0,0 +1,16 @@
+---
+'@tanstack/hotkeys': minor
+'@tanstack/hotkeys-devtools': minor
+'@tanstack/alpine-hotkeys': patch
+'@tanstack/angular-hotkeys': patch
+'@tanstack/ember-hotkeys': patch
+'@tanstack/lit-hotkeys': patch
+'@tanstack/octane-hotkeys': patch
+'@tanstack/preact-hotkeys': patch
+'@tanstack/react-hotkeys': patch
+'@tanstack/solid-hotkeys': patch
+'@tanstack/svelte-hotkeys': patch
+'@tanstack/vue-hotkeys': patch
+---
+​
+`validateHotkey` and the recorder now return reason codes instead of English text, so apps write their own messages. Each error and warning from `validateHotkey` is a `HotkeyIssue` such as `{ reason: 'unknown-modifier', part: 'Ctl' }`, and issues in a sequence carry the index of their `step` instead of a `Step 2:` prefix. A `RecorderRejection` keeps its `reason` but no longer has a built-in `message`. It has a `message` only when your `validate` callback returns one. The `'invalid'` rejection reason is now `'whitespace'`. The devtools panel lists each problem in a hotkey's details, in plain words. Console warnings and thrown errors are now one short line that starts with `[hotkeys]`. Development warnings no longer throw a `ReferenceError` where `process` is undefined, such as plain ESM loaded from a CDN.
5 additions and 0 deletions.changeset/reject-unusable-hotkeys.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/hotkeys': minor
+---
+​
+A hotkey with an unknown modifier or no key besides modifiers now registers nothing, and `validateHotkey` reports both as errors. Before, an unknown modifier was dropped, so `Ctl+K` from plain JavaScript or saved data fired on a bare K. `parseHotkey` now returns an empty key for it, so `normalizeHotkey` and `formatForDisplay` return an empty string. Modifier-only hotkeys such as `Shift+Alt+Mod` never fired, and a modifier code such as `[ShiftLeft]` fired on every Shift release. The types no longer accept modifier codes such as `[ShiftLeft]` as a key. Use the held-key APIs to act while modifiers are held.
5 additions and 0 deletions.changeset/stacked-dialog-escape.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/hotkeys': patch
+---