Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/app-hotkey-call-site-meta.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tanstack/hotkeys': minor
---

App hotkey registrations accept `meta`, which merges over the declared meta, and over `useHotkeys` common meta, for that registration only. A shared hotkey such as `list.focus-search` can register with `{ meta: { name: 'Search tables' } }` on one page. Registration lists, such as `useHotkeyRegistrations()`, show the merged meta; app hotkey lists and settings keep the declared one.
5 changes: 5 additions & 0 deletions .changeset/enabled-getter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tanstack/hotkeys': minor
---

`enabled` accepts a function, such as `enabled: () => dialog.open`. It is read on each key press, on `trigger()`, and when registration views report `status`. A `keydown` hotkey whose getter turns true during a key press doesn't fire on that press, the same as `setOptions({ enabled: true })`; a `keyup` chord still fires on that press's release. A getter that throws counts as `false` and is reported. The result changing doesn't notify registration subscribers, so lists show `status` as of their last update. In Vue, a getter is a reactive source, as for other Vue options.
6 changes: 6 additions & 0 deletions .changeset/hotkey-trigger.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@tanstack/hotkeys': minor
'@tanstack/hotkeys-devtools': patch
---

Add `trigger()` to run a registration's callback without a key press, such as from a command palette. It is on registration views, such as those from `useHotkeyRegistrations()`, on the handle `register` returns, and on the manager as `trigger(id)`. The callback gets the same context as a key press and, unless you pass an event, a `keydown` for the hotkey (a `keyup` for a keyup hotkey) that is never dispatched. Only `enabled` is checked; scopes, focus, `ignoreInputs`, and `requireReset` don't apply, and `preventDefault` and `stopPropagation` aren't applied to the event. Triggering a sequence ends its attempt in progress. The devtools Trigger button now uses it, so it no longer runs disabled hotkeys.
1,355 changes: 769 additions & 586 deletions .intent/review-state.json

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions _artifacts/domain_map.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,23 @@ skills:
source: docs/framework/react/guides/app-hotkeys.md
priority: HIGH
status: active
- mistake: Keeping a command palette action map beside the registrations
mechanism: App hotkeys hold no callback, so a palette that stores its own copy of each action drifts from the mounted components and lists actions whose components are gone.
wrong_pattern: "const commands = [{ id: 'doc.save', run: save }] // registered separately with useHotkey"
correct_pattern: "useHotkeyRegistrations().flatMap((reg) => { const name = reg.options.meta?.name; return name && reg.status !== 'disabled' ? [{ name, run: () => reg.trigger() }] : [] })"
source: src/hotkey-manager.ts (trigger); docs/framework/react/guides/cheat-sheet-ui-helpers.md
priority: HIGH
status: active
skills:
- app-hotkeys
- hotkeys-core
- mistake: Declaring a copy of a shared hotkey per page
mechanism: One app hotkey per page splits the user's custom binding and settings row for what is one shortcut.
wrong_pattern: "defineAppHotkeys({ 'tables.search': { hotkey: 'Shift+F' }, 'roles.search': { hotkey: 'Shift+F' } })"
correct_pattern: "useHotkey(appHotkeys['list.search'], focus, { meta: { name: 'Search tables' } })"
source: src/adapter.ts (prepareHotkeyDefinitions)
priority: MEDIUM
status: active
- mistake: Registering the app hotkey value instead of the app hotkey
mechanism: The declared default ignores the user custom hotkey, and the registration loses its id, meta, scope, and options, so the list reports it as inactive.
wrong_pattern: useHotkey(appHotkeys['doc.save'].hotkey as HotkeyChord, save)
Expand Down
10 changes: 9 additions & 1 deletion _artifacts/skill_spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ The skills teach agents to use those APIs directly. The core skills hold the fra
| 12 | A second copy of @tanstack/hotkeys | MEDIUM | src/_manager-ref.ts | — |
| 13 | Testing without a fixed platform | MEDIUM | src/platform.ts, runtime probe | — |

### app-hotkeys (8 failure modes)
### app-hotkeys (10 failure modes)

| # | Mistake | Priority | Source | Cross-skill? |
| --- | ------------------------------------------------ | -------- | ---------------------------------- | -------------------- |
Expand All @@ -61,6 +61,8 @@ The skills teach agents to use those APIs directly. The core skills hold the fra
| 6 | Sharing keys without declared scopes | MEDIUM | src/app-hotkeys.ts | — |
| 7 | A recorder built from keydown events | HIGH | guides/custom-hotkey-recording.md | — |
| 8 | Rewriting recorded physical bindings | MEDIUM | sensible-defaults.md | — |
| 9 | A palette that keeps its own action map | HIGH | src/hotkey-manager.ts (trigger) | hotkeys-core |
| 10 | Declaring a copy of a shared hotkey per page | MEDIUM | src/adapter.ts (call-site meta) | — |

### Framework skills

Expand Down Expand Up @@ -209,3 +211,9 @@ The skills teach agents to use those APIs directly. The core skills hold the fra
- **Source:** branch `feat/format-for-aria` from `d7e198df`. Core adds `formatForAria`, which formats a hotkey as an `aria-keyshortcuts` value, and each adapter has an ARIA formatter beside its label primitive, such as `useFormatForAria`, plus a deprecated plain `formatForAria` export like `formatForDisplay`. `HotkeyManager.suspendCharacterKeys()` and a `suspendCharacterKeys` provider option suspend character key shortcuts for WCAG 2.1.4, and suspended hotkeys report `'suspended'`. Each framework has a new Accessibility guide.
- **Changes:** every framework skill gains an API table row for its ARIA formatter, which returns `undefined` while the hotkey can't fire, and says its plain `formatForAria` export is deprecated. The seven adapters with a provider list `suspendCharacterKeys` in the provider row and say it applies app-wide. `hotkeys-core` replaces the advice to pass `enabled` for WCAG 2.1.4 with `suspendCharacterKeys`, and gains rows for a hand-written `aria-keyshortcuts` value and a hand-written single-key off switch. `domain_map.yaml` and `skill_tree.yaml` are unchanged: no failure mode or scope decision moved.
- **Checks:** `packages/hotkeys/tests/format-aria.test.ts` and `character-keys.test.ts` cover the formatter and the suspension; the shared conformance suite covers each adapter's ARIA formatter and provider option; each adapter tests that its deprecated export is the core function. `intent validate` passes. Not run: fresh-consumer sessions.

### Source sync — 2026-11-29 — command palettes and enabled getters

- **Source:** branch `feat/hotkey-trigger` from `7cf53a0c`. Registration views, registration handles, and `HotkeyManager` gain `trigger()`, which runs the registered callback without a key press with the key press's context, a synthetic event for the hotkey when none is passed, and only `enabled` checked. The devtools Trigger button uses it. App hotkey registrations accept call-site `meta`, merged over the declared meta for that registration only. `enabled` accepts a getter, read on each key press, on `trigger()`, and when views report `status`.
- **Changes:** `app-hotkeys` gains two pitfalls: a command palette runs registrations with `view.trigger()` instead of keeping its own action map, and a shared hotkey gets a page-specific name with call-site `meta` instead of a copy per page. `hotkeys-core` gains a table row for a palette that copies each shortcut's action. `references/scopes.md` describes `'disabled'` for getters. `domain_map.yaml` records both failure modes. Framework skills are unchanged: none claims `meta` comes only from the declaration, and Vue already resolves a getter `enabled` as a reactive source. `skill_tree.yaml` is unchanged.
- **Checks:** `packages/hotkeys/tests/trigger.test.ts` covers `trigger()`, getters, and the meta merge; React and Preact app hotkey tests cover call-site meta through an adapter. `intent validate` passes. Not run: fresh-consumer sessions.
2 changes: 1 addition & 1 deletion docs/framework/alpine/guides/app-hotkeys.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Alpine.data('editor', () => ({

Both forms use the effective hotkey for that id, so a user's custom hotkey applies even to a direct import, such as `this.hotkeys.createHotkey(appHotkeys['doc.save'], save)`. Without `provideAppHotkeys`, the declared default is used.

The registration takes `meta` and `options` from the declaration. Options merge in this order: the owner's defaults, then declared options, then call-site options. `meta` comes only from the declaration, so the cheat sheet and the registration cannot disagree. Call-site options are typed by the declared default's kind, so `timeout` is accepted for `nav.home` but not for `doc.save`.
The registration takes `meta` and `options` from the declaration. Options merge in this order: the owner's defaults, then declared options, then call-site options. `meta` comes from the declaration. Call-site `meta` adds to it for that registration only, such as a page-specific `name` for a shared hotkey: registration lists show the merged meta, and app hotkey lists keep the declared one. Call-site options are typed by the declared default's kind, so `timeout` is accepted for `nav.home` but not for `doc.save`.

When a component registers several hotkeys, pass app hotkeys to `createHotkeys` in the same field, and mix in plain hotkeys as needed:

Expand Down
15 changes: 12 additions & 3 deletions docs/framework/alpine/guides/cheat-sheet-ui-helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ this.hotkeys.createHotkeys([
`meta` is typed as `HotkeyMeta`. To add fields of your own, such as an icon, extend it with declaration merging:

```ts
declare module '@tanstack/hotkeys' {
declare module '@tanstack/alpine-hotkeys' {
interface HotkeyMeta {
icon?: string
}
Expand Down Expand Up @@ -94,14 +94,23 @@ Alpine.data('shortcutList', () => {

Filtering by name leaves out hotkeys you didn't mean to list, such as a dialog's `Escape`. Filtering by `status` leaves only the hotkeys that are on right now.

`status` is `'active'` when the hotkey is enabled and nothing suspends it, `'suspended'` when its [scope](./hotkey-manager#activate-a-scope) is inactive or suspended by an exclusive scope or it is a document-level character key shortcut while [character keys are suspended](./accessibility#turn-them-off), and `'disabled'` when it has `enabled: false`. `createHotkeyRegistrations` updates when scopes change, so the list stays current.
`status` is `'active'` when the hotkey is enabled and nothing suspends it, `'suspended'` when its [scope](./hotkey-manager#activate-a-scope) is inactive or suspended by an exclusive scope or it is a document-level character key shortcut while [character keys are suspended](./accessibility#turn-them-off), and `'disabled'` when `enabled` is `false`, or its getter returned `false` when the list last updated. `createHotkeyRegistrations` updates when scopes change, so the list stays current.

Each registration view has an `id`, the `hotkey`, a `status`, its `options` (including `meta`, `enabled`, and `scope`), its `target`, and a `triggerCount`. Narrow with `kind`: chord views add `parsedChord`, and sequence views add `parsedSequence` and `matchedStepCount`, the number of steps the user has pressed so far. [Show sequences in your UI](./sequences#show-sequences-in-your-ui) uses it to show which keys the user has pressed.
Each registration view has an `id`, the `hotkey`, a `status`, its `options` (including `meta`, `enabled`, and `scope`), its `target`, a `triggerCount`, and [`trigger()`](#run-hotkeys-from-a-command-palette). Narrow with `kind`: chord views add `parsedChord`, and sequence views add `parsedSequence` and `matchedStepCount`, the number of steps the user has pressed so far. [Show sequences in your UI](./sequences#show-sequences-in-your-ui) uses it to show which keys the user has pressed.

A hotkey that several components register, such as one per list row, appears once for each registration.

Registrations exist only while their owners exist, so this list can't show shortcuts from other pages. To list those, declare them as app hotkeys.


## Run hotkeys from a command palette

Each entry has `trigger()`, which runs the registered callback without a key press, so a command palette can list the mounted hotkeys and run the one a user picks. The callback gets the same context as a key press, and a `keydown` event for the hotkey (a `keyup` for a hotkey registered with `eventType: 'keyup'`) that is never dispatched, so its `target` is `null`. Pass your own event, such as `trigger(event)`, to use that one instead.

`trigger()` checks only `enabled` and returns whether the callback ran. It runs a hotkey whose scope is suspended, because a palette usually owns the keyboard while it is open, and it doesn't apply `preventDefault` or `stopPropagation` to the event. It counts toward `triggerCount` and ends a sequence's attempt in progress.
Comment thread
KevinVandy marked this conversation as resolved.
Resolved

Filter the palette's list with `status !== 'disabled'`, not `status === 'active'`: a palette that opens its own exclusive scope suspends the other hotkeys, and `trigger()` still runs them. A hotkey with an `enabled` getter shows the status from the list's last update, so the palette can hide a command whose getter has since turned true.

## List every app hotkey

`createAppHotkeyList` returns every app hotkey in declaration order, whether or not anything has registered it. Each item has the `appHotkey`, with its current `hotkey` and its `meta`, plus a `status` and `isCustom`, which is `true` when the user changed the hotkey:
Expand Down
2 changes: 2 additions & 0 deletions docs/framework/alpine/guides/hotkeys.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ Alpine.data('settingsDialog', () => ({
}))
```

`enabled` also takes a function, read each time a key is pressed, for state that lives outside your framework, such as `enabled: () => editor.hasFocus()`. A `keydown` hotkey whose function turns true during a key press doesn't fire on that press, as with `enabled: true` set then; a `keyup` chord still fires on that press's release, to end a mode. A function that throws counts as `false`. Lists that show `status`, such as a cheat sheet, show the function's result as of their last update. Keep the function cheap, because it runs on every key press.

```html
<template x-if="isOpen">
<div x-data="settingsDialog" role="dialog" @close="isOpen = false">...</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Registers a hotkey: a chord, a sequence, or an app hotkey.

#### options?

`MaybeGetter`\<[`AlpineAppHotkeyOptions`](../type-aliases/AlpineAppHotkeyOptions.md)\<`T`\>\>
`MaybeGetter`\<`AdapterAppHotkeyOptions`\<`T`, [`AlpineHotkeyTarget`](../type-aliases/AlpineHotkeyTarget.md)\>\>

### Returns

Expand Down
2 changes: 1 addition & 1 deletion docs/framework/angular/guides/app-hotkeys.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class EditorComponent {
Inside `provideHotkeys`, `injectAppHotkeys()` and direct imports (such as `injectHotkey(appHotkeys['doc.save'], save)`) both resolve to the user's current custom binding. Without a provider, direct imports fall back to the declared defaults, while `injectAppHotkeys()` requires `provideHotkeys` with `appHotkeys`. When a user rebinds an app hotkey, active registrations update immediately, even when switching between a chord and a sequence.

- **Option merging.** Options merge in order from provider `defaultOptions`, then declared `options`, then call-site options. Call-site options are typed against the declared default's kind, so `timeout` is accepted for `nav.home` but not for `doc.save`.
- **Metadata.** `meta` always comes from the declaration so cheat sheets and handlers stay in sync.
- **Metadata.** `meta` comes from the declaration. Pass `meta` at the call site to add to it for that registration only, such as `{ name: 'Search tables' }` on one page of a shared `list.focus-search` hotkey. Registration lists show the merged meta; app hotkey lists and settings keep the declared one.

Mix app hotkeys and regular hotkeys freely in `injectHotkeys`:

Expand Down
15 changes: 12 additions & 3 deletions docs/framework/angular/guides/cheat-sheet-ui-helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ injectHotkeys([
`meta` doesn't affect key matching. It feeds your UI lists and shows up in devtools. To add custom fields like `icon`, augment `HotkeyMeta`:

```ts
declare module '@tanstack/hotkeys' {
declare module '@tanstack/angular-hotkeys' {
interface HotkeyMeta {
icon?: string
}
Expand Down Expand Up @@ -91,9 +91,18 @@ Filtering by `meta?.name` omits unnamed helper shortcuts, such as a dialog's `Es

- `'active'` means the hotkey is enabled and nothing suspends it
- `'suspended'` means it is enabled, but its [scope](./provide-hotkeys-and-scopes) is inactive or suspended by an exclusive scope, or it is a document-level character key shortcut while [character keys are suspended](./accessibility#turn-them-off)
- `'disabled'` means `enabled: false` was set
- `'disabled'` means `enabled` is `false`, or its getter returned `false` when the list last updated

Each entry also includes `id`, `hotkey`, `options`, `target`, and `triggerCount`. Chord entries (`kind === 'chord'`) add `parsedChord`, and sequence entries (`kind === 'sequence'`) add `parsedSequence` and `matchedStepCount` (used in [Show sequences in your UI](./sequences#show-sequences-in-your-ui)). If several components register the same shortcut, such as rows in a list, each registration appears as its own entry.
Each entry also includes `id`, `hotkey`, `options`, `target`, `triggerCount`, and [`trigger()`](#run-hotkeys-from-a-command-palette). Chord entries (`kind === 'chord'`) add `parsedChord`, and sequence entries (`kind === 'sequence'`) add `parsedSequence` and `matchedStepCount` (used in [Show sequences in your UI](./sequences#show-sequences-in-your-ui)). If several components register the same shortcut, such as rows in a list, each registration appears as its own entry.


## Run hotkeys from a command palette

Each entry has `trigger()`, which runs the registered callback without a key press, so a command palette can list the mounted hotkeys and run the one a user picks. The callback gets the same context as a key press, and a `keydown` event for the hotkey (a `keyup` for a hotkey registered with `eventType: 'keyup'`) that is never dispatched, so its `target` is `null`. Pass your own event, such as `trigger(event)`, to use that one instead.

`trigger()` checks only `enabled` and returns whether the callback ran. It runs a hotkey whose scope is suspended, because a palette usually owns the keyboard while it is open, and it doesn't apply `preventDefault` or `stopPropagation` to the event. It counts toward `triggerCount` and ends a sequence's attempt in progress.
Comment thread
KevinVandy marked this conversation as resolved.
Resolved

Filter the palette's list with `status !== 'disabled'`, not `status === 'active'`: a palette that opens its own exclusive scope suspends the other hotkeys, and `trigger()` still runs them. A hotkey with an `enabled` getter shows the status from the list's last update, so the palette can hide a command whose getter has since turned true.

## List every app hotkey

Expand Down
2 changes: 1 addition & 1 deletion docs/framework/angular/reference/functions/injectHotkey.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ such as `() => this.shortcut()`; when it changes to a hotkey, it registers.

#### options?

`MaybeGetter`\<[`InjectAppHotkeyOptions`](../type-aliases/InjectAppHotkeyOptions.md)\<`T`\>\>
`MaybeGetter`\<`AdapterAppHotkeyOptions`\<`T`, [`InjectHotkeyTarget`](../type-aliases/InjectHotkeyTarget.md)\>\>

### Returns

Expand Down
Loading
Loading