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/tidy-tigers-swim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tanstack/hotkeys': patch
---

Preserve native button Space/Enter and link Enter activation when global hotkeys or sequences ignore inputs. Explicit element targets and ignoreInputs: false can still override these keys.
2 changes: 2 additions & 0 deletions docs/framework/angular/guides/hotkeys.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ injectHotkey('Escape', () => closePanel(), { requireReset: true })

### `ignoreInputs`

When `ignoreInputs` is enabled, global hotkeys and sequences (targeting `document` or `window`) also preserve unmodified `Space` and `Enter` on native buttons and button-type inputs, and `Enter` on links with an `href`. Other keys and modifier shortcuts still work on these controls. Set `ignoreInputs: false`, or use an explicit element `target`, to intentionally handle their activation keys. This does not automatically detect keyboard handling in custom ARIA widgets.

```ts
injectHotkey('K', () => openSearch())
injectHotkey('Enter', () => submit(), { ignoreInputs: false })
Expand Down
4 changes: 3 additions & 1 deletion docs/framework/lit/guides/hotkeys.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ closePanel() { this.panelOpen = false }

### `ignoreInputs`

When `true`, the hotkey doesn't fire when the user is focused on a text input, textarea, select, or contentEditable element. Button-type inputs (`type="button"`, `"submit"`, `"reset"`) are not ignored. When unset, a smart default applies: `Ctrl`/`Meta` shortcuts and `Escape` fire in inputs; single keys and `Shift`/`Alt` combos are ignored.
When `ignoreInputs` is enabled, global hotkeys and sequences (targeting `document` or `window`) also preserve unmodified `Space` and `Enter` on native buttons and button-type inputs, and `Enter` on links with an `href`. Other keys and modifier shortcuts still work on these controls. Set `ignoreInputs: false`, or use an explicit element `target`, to intentionally handle their activation keys. This does not automatically detect keyboard handling in custom ARIA widgets.

When `true`, the hotkey doesn't fire when the user is focused on a text input, textarea, select, or contentEditable element. Button-type inputs (`type="button"`, `"submit"`, `"reset"`) allow unrelated shortcuts. When unset, a smart default applies: `Ctrl`/`Meta` shortcuts and `Escape` fire in inputs; single keys and `Shift`/`Alt` combos are ignored.

```ts
// Single key - ignored in inputs by default (smart default)
Expand Down
4 changes: 3 additions & 1 deletion docs/framework/preact/guides/hotkeys.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ useHotkey('Escape', () => closePanel(), { requireReset: true })

### `ignoreInputs`

When `true`, the hotkey doesn't fire when the user is focused on a text input, textarea, select, or contentEditable element. Button-type inputs (`type="button"`, `"submit"`, `"reset"`) are not ignored, so shortcuts like Mod+S work when the user has tabbed to a form button. When unset, a smart default applies: `Ctrl`/`Meta` shortcuts and `Escape` fire in inputs; single keys and `Shift`/`Alt` combos are ignored.
When `ignoreInputs` is enabled, global hotkeys and sequences (targeting `document` or `window`) also preserve unmodified `Space` and `Enter` on native buttons and button-type inputs, and `Enter` on links with an `href`. Other keys and modifier shortcuts still work on these controls. Set `ignoreInputs: false`, or use an explicit element `target`, to intentionally handle their activation keys. This does not automatically detect keyboard handling in custom ARIA widgets.

When `true`, the hotkey doesn't fire when the user is focused on a text input, textarea, select, or contentEditable element. Button-type inputs (`type="button"`, `"submit"`, `"reset"`) allow unrelated shortcuts, so shortcuts like Mod+S work when the user has tabbed to a form button. When unset, a smart default applies: `Ctrl`/`Meta` shortcuts and `Escape` fire in inputs; single keys and `Shift`/`Alt` combos are ignored.

```tsx
// Single key - ignored in inputs by default (smart default)
Expand Down
6 changes: 4 additions & 2 deletions docs/framework/react/guides/hotkeys.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Most hotkey registrations exist to override the browser. When you bind `Mod+S` t

#### Smart input handling with `ignoreInputs`

By default, `Ctrl`/`Meta` shortcuts (like `Mod+S`) and `Escape` fire even while focus is inside a text field or textarea, so save and close work wherever the user happens to be. Single keys and `Shift`/`Alt` combos are ignored inside non-button inputs, because those are just typing. Button-type inputs (`type="button"`, `"submit"`, `"reset"`) don't block any hotkeys.
By default, `Ctrl`/`Meta` shortcuts (like `Mod+S`) and `Escape` fire even while focus is inside a text field or textarea, so save and close work wherever the user happens to be. Single keys and `Shift`/`Alt` combos are ignored inside non-button inputs, because those are just typing. Button-type inputs (`type="button"`, `"submit"`, `"reset"`) allow unrelated shortcuts while preserving their native activation keys.

#### Hotkey conflicts and `conflictBehavior`

Expand Down Expand Up @@ -165,7 +165,9 @@ useHotkey('Escape', () => closePanel(), { requireReset: true })

### `ignoreInputs`

When `true`, the hotkey will not fire when the user is focused on a text input, textarea, select, or contentEditable element. Button-type inputs (`type="button"`, `"submit"`, `"reset"`) are not ignored, so shortcuts like Mod+S work when the user has tabbed to a form button. When unset, a smart default applies: `Ctrl`/`Meta` shortcuts and `Escape` fire in inputs; single keys and `Shift`/`Alt` combos are ignored.
When `ignoreInputs` is enabled, global hotkeys and sequences (targeting `document` or `window`) also preserve unmodified `Space` and `Enter` on native buttons and button-type inputs, and `Enter` on links with an `href`. Other keys and modifier shortcuts still work on these controls. Set `ignoreInputs: false`, or use an explicit element `target`, to intentionally handle their activation keys. This does not automatically detect keyboard handling in custom ARIA widgets.

When `true`, the hotkey will not fire when the user is focused on a text input, textarea, select, or contentEditable element. Button-type inputs (`type="button"`, `"submit"`, `"reset"`) allow unrelated shortcuts, so shortcuts like Mod+S work when the user has tabbed to a form button. When unset, a smart default applies: `Ctrl`/`Meta` shortcuts and `Escape` fire in inputs; single keys and `Shift`/`Alt` combos are ignored.

```tsx
// Single key - ignored in inputs by default (smart default)
Expand Down
2 changes: 2 additions & 0 deletions docs/framework/solid/guides/hotkeys.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ createHotkey('Escape', () => closePanel(), { requireReset: true })

### `ignoreInputs`

When `ignoreInputs` is enabled, global hotkeys and sequences (targeting `document` or `window`) also preserve unmodified `Space` and `Enter` on native buttons and button-type inputs, and `Enter` on links with an `href`. Other keys and modifier shortcuts still work on these controls. Set `ignoreInputs: false`, or use an explicit element `target`, to intentionally handle their activation keys. This does not automatically detect keyboard handling in custom ARIA widgets.

When `true`, the hotkey doesn't fire when the user is focused on a text input, textarea, select, or contentEditable element. When unset, a smart default applies based on the hotkey type.

```tsx
Expand Down
2 changes: 2 additions & 0 deletions docs/framework/svelte/guides/hotkeys.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ createHotkey('Escape', () => closePanel(), { requireReset: true })

### `ignoreInputs`

When `ignoreInputs` is enabled, global hotkeys and sequences (targeting `document` or `window`) also preserve unmodified `Space` and `Enter` on native buttons and button-type inputs, and `Enter` on links with an `href`. Other keys and modifier shortcuts still work on these controls. Set `ignoreInputs: false`, or use an explicit element `target`, to intentionally handle their activation keys. This does not automatically detect keyboard handling in custom ARIA widgets.

```ts
createHotkey('K', () => openSearch())
createHotkey('Enter', () => submit(), { ignoreInputs: false })
Expand Down
2 changes: 2 additions & 0 deletions docs/framework/vue/guides/hotkeys.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ useHotkey('Escape', () => closePanel(), { requireReset: true })

### `ignoreInputs`

When `ignoreInputs` is enabled, global hotkeys and sequences (targeting `document` or `window`) also preserve unmodified `Space` and `Enter` on native buttons and button-type inputs, and `Enter` on links with an `href`. Other keys and modifier shortcuts still work on these controls. Set `ignoreInputs: false`, or use an explicit element `target`, to intentionally handle their activation keys. This does not automatically detect keyboard handling in custom ARIA widgets.

```ts
useHotkey('K', () => openSearch())
useHotkey('Enter', () => submit(), { ignoreInputs: false })
Expand Down
18 changes: 9 additions & 9 deletions docs/reference/classes/HotkeyManager.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ id: HotkeyManager
title: HotkeyManager
---

Defined in: [hotkey-manager.ts:191](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L191)
Defined in: [hotkey-manager.ts:197](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L197)

Singleton manager for hotkey registrations.

Expand Down Expand Up @@ -32,7 +32,7 @@ unregister()
readonly registrations: Store<Map<string, HotkeyRegistration>>;
```

Defined in: [hotkey-manager.ts:213](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L213)
Defined in: [hotkey-manager.ts:219](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L219)

The TanStack Store containing all hotkey registrations.
Use this to subscribe to registration changes or access current registrations.
Expand Down Expand Up @@ -61,7 +61,7 @@ for (const [id, reg] of manager.registrations.state) {
destroy(): void;
```

Defined in: [hotkey-manager.ts:796](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L796)
Defined in: [hotkey-manager.ts:802](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L802)

Destroys the manager and removes all listeners.

Expand All @@ -77,7 +77,7 @@ Destroys the manager and removes all listeners.
getRegistrationCount(): number;
```

Defined in: [hotkey-manager.ts:761](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L761)
Defined in: [hotkey-manager.ts:767](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L767)

Gets the number of registered hotkeys.

Expand All @@ -93,7 +93,7 @@ Gets the number of registered hotkeys.
isRegistered(hotkey, target?): boolean;
```

Defined in: [hotkey-manager.ts:772](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L772)
Defined in: [hotkey-manager.ts:778](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L778)

Checks if a specific hotkey is registered.

Expand Down Expand Up @@ -128,7 +128,7 @@ register(
options?): HotkeyRegistrationHandle;
```

Defined in: [hotkey-manager.ts:276](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L276)
Defined in: [hotkey-manager.ts:282](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L282)

Registers a hotkey handler and returns a handle for updating the registration.

Expand Down Expand Up @@ -184,7 +184,7 @@ handle.unregister()
triggerRegistration(id): boolean;
```

Defined in: [hotkey-manager.ts:723](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L723)
Defined in: [hotkey-manager.ts:729](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L729)

Triggers a registration's callback programmatically from devtools.
Creates a synthetic KeyboardEvent and invokes the callback.
Expand All @@ -211,7 +211,7 @@ True if the registration was found and triggered
static getInstance(): HotkeyManager;
```

Defined in: [hotkey-manager.ts:234](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L234)
Defined in: [hotkey-manager.ts:240](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L240)

Gets the singleton instance of HotkeyManager.

Expand All @@ -227,7 +227,7 @@ Gets the singleton instance of HotkeyManager.
static resetInstance(): void;
```

Defined in: [hotkey-manager.ts:244](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L244)
Defined in: [hotkey-manager.ts:250](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L250)

Resets the singleton instance. Useful for testing.

Expand Down
2 changes: 1 addition & 1 deletion docs/reference/functions/getHotkeyManager.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ title: getHotkeyManager
function getHotkeyManager(): HotkeyManager;
```

Defined in: [hotkey-manager.ts:812](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L812)
Defined in: [hotkey-manager.ts:818](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L818)

Gets the singleton HotkeyManager instance.
Convenience function for accessing the manager.
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/functions/toHotkeyRegistrationView.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ title: toHotkeyRegistrationView
function toHotkeyRegistrationView(reg): HotkeyRegistrationView;
```

Defined in: [hotkey-manager.ts:107](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L107)
Defined in: [hotkey-manager.ts:113](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L113)

Creates a public view from an internal registration,
stripping the callback function.
Expand Down
20 changes: 12 additions & 8 deletions docs/reference/interfaces/HotkeyOptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,13 @@ The event type to listen for. Defaults to 'keydown'
optional ignoreInputs?: boolean;
```

Defined in: [hotkey-manager.ts:43](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L43)
Defined in: [hotkey-manager.ts:49](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L49)

Whether to ignore hotkeys when keyboard events originate from input-like elements (text inputs, textarea, select, contenteditable — button-type inputs like type=button/submit/reset are not ignored). Defaults based on hotkey: true for single keys and Shift/Alt combos; false for Ctrl/Meta shortcuts and Escape
Ignore events from text inputs, textarea, select, and contenteditable.
Document/window targets also preserve unmodified Space/Enter on native
buttons and Enter on links. Explicit element targets can override activation.
Defaults to true for single keys and Shift/Alt combos; false for Ctrl/Meta
shortcuts and Escape. Set false to handle keys even in these controls.

***

Expand All @@ -65,7 +69,7 @@ Whether to ignore hotkeys when keyboard events originate from input-like element
optional meta?: HotkeyMeta;
```

Defined in: [hotkey-manager.ts:55](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L55)
Defined in: [hotkey-manager.ts:61](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L61)

Optional metadata (name, description, custom fields via declaration merging)

Expand All @@ -77,7 +81,7 @@ Optional metadata (name, description, custom fields via declaration merging)
optional platform?: "mac" | "windows" | "linux";
```

Defined in: [hotkey-manager.ts:45](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L45)
Defined in: [hotkey-manager.ts:51](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L51)

The target platform for resolving 'Mod'

Expand All @@ -89,7 +93,7 @@ The target platform for resolving 'Mod'
optional preventDefault?: boolean;
```

Defined in: [hotkey-manager.ts:47](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L47)
Defined in: [hotkey-manager.ts:53](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L53)

Prevent the default browser action when the hotkey matches. Defaults to true

Expand All @@ -101,7 +105,7 @@ Prevent the default browser action when the hotkey matches. Defaults to true
optional requireReset?: boolean;
```

Defined in: [hotkey-manager.ts:49](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L49)
Defined in: [hotkey-manager.ts:55](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L55)

If true, only trigger once until all keys are released. Default: false

Expand All @@ -113,7 +117,7 @@ If true, only trigger once until all keys are released. Default: false
optional stopPropagation?: boolean;
```

Defined in: [hotkey-manager.ts:51](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L51)
Defined in: [hotkey-manager.ts:57](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L57)

Stop event propagation when the hotkey matches. Defaults to true

Expand All @@ -125,6 +129,6 @@ Stop event propagation when the hotkey matches. Defaults to true
optional target?: Document | Window | HTMLElement | null;
```

Defined in: [hotkey-manager.ts:53](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L53)
Defined in: [hotkey-manager.ts:59](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L59)

The DOM element to attach the event listener to. Defaults to document.
Loading
Loading