TanStack Hotkeys chooses defaults so common shortcuts need no configuration. Without any options, Mod+S maps to Command+S on macOS and Control+S elsewhere, blocks the browser's Save dialog, keeps working inside text fields, and matches across keyboard layouts.
This guide explains each default and how to override it.
| Behavior | Default | Change it with |
|---|---|---|
| Mod modifier | Command on macOS, Control on Windows and Linux | platform |
| Key identity | Character the key types (event.key), with position fallback | [KeyS] physical bindings |
| Modifiers | Exact match required | List every modifier in the binding |
| Typing in inputs | Single keys and Shift or Alt chords ignored, while Control or Meta chords, Escape, function keys, and media keys fire | ignoreInputs |
| Browser behavior | Calls preventDefault() and stopPropagation() when matched | preventDefault, stopPropagation |
| Disabled or inactive hotkeys | Browser acts on the key | preventDefault: 'always' |
| When a chord fires | On keydown, and on auto-repeat while held | eventType, requireReset |
| Listener target | document | target |
| Event phase | Bubble phase (after widget handlers inside target) | capture |
| Already-prevented keys | Hotkeys still fire | ignoreDefaultPrevented |
| Sequence step timeout | 1 second (1000 ms) | timeout |
| Duplicate registrations | Allowed, with a development console warning | conflictBehavior |
| Recording | Portable name or physical fallback. Escape, Tab, Shift+Tab cancel | recordBy, recordTab, recorder options |
| Display formatting | Symbols on macOS (⇧ ⌘ S), text elsewhere (Ctrl+Shift+S) | Label formatter options (such as useFormatForDisplay) |
Mod resolves to the platform's primary shortcut modifier: Command (Meta) on macOS, and Control on Windows and Linux. A single Mod+S binding adapts to each user's operating system automatically.
Logical bindings like Mod+S or ? match event.key, which is the character produced on the user's active keyboard layout. Matching is case-insensitive, so S and s are identical. A user on Dvorak, Colemak, or AZERTY presses the key labeled S to trigger Mod+S, wherever it sits physically.
event.key doesn't always tell you which key was pressed, so the matcher falls back to the key's position (event.code or keycap identity) in four cases:
Outside the fallbacks above, the character the key types wins even if that key sits in a different spot than on US QWERTY:
When a shortcut should follow physical keyboard geometry instead of characters, such as W, A, S, D game movement, use a physical binding. Physical bindings match event.code directly and ignore layout:
| Binding | Matches |
|---|---|
| Mod+S or { key: 'S', mod: true } | The character S (event.key), with the fallbacks above |
| Mod+[KeyS] or { code: 'KeyS', mod: true } | The physical S key on a US layout (event.code) |
| Enter | Either Enter key, including the numpad's |
| [Enter] or [NumpadEnter] | Only that specific Enter key |
By default, hotkey strings type-check against US QWERTY keys. Most apps never need to change this, because A to Z, 0 to 9, and common US punctuation already match across international layouts at runtime.
To type-check layout-specific keys such as Ö, ß, or §, register those layout sets through module augmentation (see your framework's Keyboard Layouts guide). Registering sets changes types only. Matching behavior and bundle size stay identical.
Each set covers layout-specific keys and punctuation typed unshifted or with Shift across Windows, macOS, and Linux, omitting dead keys and AltGr or Option characters. Letters typed with Shift require Shift+ in the hotkey.
Polish and Latvian share US QWERTY base keys without AltGr, and most Dutch users use US International, so they don't need a separate set.
Mod+S won't fire on Mod+Shift+S, and K won't fire on Shift+K. Exact matching keeps Mod+Z (undo) and Mod+Shift+Z (redo) from colliding.
A hotkey bound to K shouldn't fire when the user types "okay" into a search box. By default, ignoreInputs is 'auto', which decides based on the hotkey itself (using the first step for sequences):
| Hotkey | Behavior in inputs | Why |
|---|---|---|
| K, Shift+K, Alt+K, ? | Ignored | These keys type text |
| ArrowLeft, Home, Backspace, Enter | Ignored | A text field uses these keys to move the caret and edit text |
| Mod+S, Control+K, Meta+Enter | Fires | Primary shortcuts shouldn't break while editing |
| Escape | Fires | Users expect Escape to close dialogs from inside inputs |
| F5, Shift+F10, MediaPlayPause | Fires | Function keys and media keys don't type text, and a text field does nothing with them |
Function keys are F1 to F24. Media keys are the keys whose names start with Audio, Browser, Launch, or Media, such as AudioVolumeMute, BrowserBack, LaunchMail, and MediaTrackNext. Both kinds fire in inputs with any modifiers. A sequence follows its first step, so ['F2', 'R'] also fires in inputs, and the R press doesn't type into the field.
These elements count as inputs, including inside open shadow roots:
Non-text controls (checkboxes, radios, ranges, color, file, and buttons) are not text inputs, so K still fires there. They only protect the specific keys they use (see below). Custom elements can set a role like role="checkbox" for the same behavior.
A hotkey whose target is the input element itself always receives its events. To let a shortcut like Enter submit a form from its text fields, set ignoreInputs: false. To ignore even Mod shortcuts inside inputs, set ignoreInputs: true.
Control and Meta chords fire in inputs, so a hotkey can take a chord that the browser uses to edit text. A Mod+Z hotkey on the document runs your undo while the user types in a text field, and the field's own undo doesn't run. These shortcuts are the ones to check:
'auto' doesn't detect these chords, because no list of them is complete. Text editing shortcuts differ between operating systems, macOS lets users rebind them, and the browser doesn't report whether a key press edits the field.
If the text field should keep the chord, set ignoreInputs: true on the hotkey. The hotkey then runs everywhere except while a text field has focus. If the hotkey belongs to one part of the page, such as a canvas or a data grid, set target to that element instead, so key presses in fields outside the element never reach the hotkey.
An editor that handles these chords itself is the opposite case. Register the hotkeys with the editor's element as the target. A hotkey always receives the events of its own target, so ignoreInputs doesn't apply.
Native controls and ARIA widgets use keys like Space, Enter, and arrow keys for themselves. When ignoreInputs is active (true or 'auto'), hotkeys skip those keys while a matching control or element inside it has focus:
| Focused control | Keys it keeps |
|---|---|
| <button>, button, image, color, and file inputs, <summary>, role="button" | Enter, Space |
| Checkbox inputs, role="checkbox", "switch", "radio" | Space |
| Radio inputs, role="radiogroup" | Arrow keys, Space |
| Range inputs, role="slider" | Arrow keys, Home, End, PageUp, PageDown |
| Read-only text inputs | ArrowLeft, ArrowRight, Home, End |
| Read-only textareas | Arrow keys, Home, End, PageUp, PageDown |
| Links with href, role="link" | Enter |
| role="tab", "option", "treeitem", "menuitem" (all forms) | Enter, Space |
| role="menu", "menubar", "tree" | Arrow keys, Home, End, Enter, Space, typeahead characters |
| role="listbox" | Vertical arrows (horizontal if aria-orientation="horizontal"), Home, End, Enter, Space, typeahead |
| role="combobox" (without a text field) | ArrowUp, ArrowDown, Home, End, Enter, Space, typeahead |
| role="tablist" | Horizontal arrows (vertical if aria-orientation="vertical"), Home, End, Enter, Space |
| role="toolbar" | Horizontal arrows (vertical if aria-orientation="vertical"), Home, End |
| role="grid", "treegrid" | Arrow keys, Home, End, PageUp, PageDown, Enter, Space |
| role="spinbutton" | ArrowUp, ArrowDown, Home, End, PageUp, PageDown |
preventDefault and stopPropagation both default to true. Binding Mod+S shouldn't open the browser's Save Page dialog, and binding Mod+K shouldn't jump to the address bar or fire duplicate listeners higher in the DOM.
If a hotkey is disabled (enabled: false) or its scope is inactive or suspended, it doesn't call preventDefault(). That means pressing Mod+S while saving is disabled opens the browser's Save dialog.
For most shortcuts, setting preventDefault: 'always' in your shared defaults is better. With 'always', a disabled or suspended chord still prevents the browser's default action:
Don't use 'always' on hotkeys you turn off specifically to hand keys back to the browser. Set preventDefault: true on those instead:
Ignoring text inputs prevents K from firing while typing, but speech-input users dictate words as single keystrokes. Under WCAG 2.1.4, any shortcut using only letters, numbers, or symbols (including Shift+K or a sequence like ['G', 'G']) must satisfy at least one of these conditions:
Shortcuts using Mod, Control, or Alt, as well as non-character keys like Escape, function keys, and media keys, don't need this.
By default, chords fire on keydown and repeat on each OS auto-repeat tick while held, which suits actions such as holding Mod+Z for undo or scrolling.
Hotkeys listen on document by default so they work regardless of focus. Internally, TanStack Hotkeys attaches at most one keydown and one keyup listener per target (plus a capture pair if any hotkey uses capture: true), no matter how many shortcuts you register.
Hotkeys listen in the bubble phase by default, so a focused widget's own onKeyDown handler runs first and can call stopPropagation().
UI libraries close dialogs, popovers, and menus on Escape, and rich-text editors handle chords like Mod+B. When your app binds the same key, a single keystroke can reach both unless they coordinate.
If a component library or editor calls preventDefault() on a key without calling stopPropagation(), your hotkey still sees the event. Set ignoreDefaultPrevented: true in your shared defaults (see Changing the defaults) so hotkeys skip any event another listener already prevented. A hotkey's own preventDefault is ignored for this check, so your element and document hotkeys still compose.
Note
ignoreDefaultPrevented only sees preventDefault() calls from listeners that run before yours (on a child element, or in the capture phase). Libraries that attach a fresh document listener only when an overlay opens run after your hotkeys, so the option can't help there. For Escape on overlays, see Let an open overlay handle Escape.
Turn on ignoreDefaultPrevented: true if you use:
React Aria, Base UI, MUI dialogs and menus, Headless UI menus and listboxes, and Monaco stop propagation on the keys they handle, so hotkeys never see them.
By default, TanStack Hotkeys keeps Escape working for the innermost open overlay. When focus is inside a modal or menu, Escape hotkeys outside it are automatically skipped (no callback, no preventDefault(), no stopPropagation()). A hotkey targeted at the overlay, or at an element inside it, still receives Escape.
TanStack Hotkeys detects overlays at window before document listeners run:
When writing your own Escape hotkeys:
Let the browser close native <dialog> and popover. Build overlays on <dialog> with showModal() or popover ("auto") without registering a custom Escape hotkey. A popover="manual" popover doesn't close on Escape, so close it with an Escape hotkey targeted at it. For a dialog users cannot dismiss, use <dialog closedby="none"> and also call preventDefault() on its cancel event for browsers without closedby.
Target custom overlays directly. For a custom ARIA dialog you manage yourself, pass target on the overlay element rather than registering a global Escape.
Guard global Escape when needed. Automatic detection can't see overlays in these cases:
Wrap those in an exclusive scope while open, or pass enabled: !open to your global Escape hotkey while keeping the default preventDefault (not 'always') so the overlay still receives Escape.
Keep Escape out of page sections and sequences. Inside role="dialog" or role="alertdialog", hotkeys in any named scope keep Escape, so a page section's Escape hotkey steals it from a library's dialog, and a sequence step on Escape competes with every overlay.
While focus is inside a role="dialog" or role="alertdialog" element, hotkeys in any named scope keep Escape (regardless of target), so a dialog component using its own scope can still close itself while an inner combobox or menu still closes first. Native <dialog> and popover overlays take Escape before any hotkey outside them regardless of scope. Make a dialog's scope exclusive if other named scopes can stay active behind it.
Tested: Radix UI and shadcn/ui dialogs and Headless UI Dialog close on Escape without triggering outer hotkeys. The first Escape in an open React Aria ComboBox closes its list, and the next runs your hotkey.
Not yet tested with this rule: Ant Design and Mantine.
See Group hotkeys into scopes to give an overlay its own scope.
A sequence like ['G', 'G'] completes when each step arrives within 1000 ms (timeout). While a sequence is in progress:
Registering two hotkeys with the same canonical binding, target, scope, and event type logs a console warning in development and runs both callbacks. Set conflictBehavior to 'replace', 'error', or 'allow' to customize this.
Dev warnings check process.env.NODE_ENV, so bundlers strip them in production. If you load the library without a bundler (no process global), use validateHotkey or assertValidHotkey to validate strings, or set conflictBehavior: 'error'.
With the default recordBy: 'auto', the hotkey recorder writes portable strings just as you would by hand. Command+S on macOS and Control+S elsewhere both record 'Mod+S'.
While recording is active:
Key state tracking updates on keydown and keyup, with automatic safeguards against stuck keys:
Label formatters like useFormatForDisplay match OS conventions. Mod+Shift+S becomes ⇧ ⌘ S on macOS and Ctrl+Shift+S on Windows and Linux, and sequence steps join with spaces (G G). Pass useSymbols: false for text names on macOS, or keyLabels to rename individual keys.
Every option above can be set per registration. To change defaults across your app, configure your framework adapter:
Pass defaultOptions to HotkeysProvider. See Hotkey options in Register Hotkeys.