Build your cheat sheet directly from your registered or declared hotkeys so the help dialog never drifts out of sync when bindings change. Format each binding with createFormatForDisplay (see Formatting & Display).
Each of these primitives covers a different cheat sheet setup:
Both return accessors. Start with createHotkeyRegistrations for smaller apps. Switch to createAppHotkeyList for an app-wide cheat sheet or user customization.
Add meta (name, plus optional description and group) to shortcuts you want displayed:
createHotkeys([
{
hotkey: 'Mod+S',
callback: () => save(),
options: { meta: { name: 'Save', group: 'File' } },
},
{
hotkey: 'Mod+Shift+S',
callback: () => saveAs(),
options: { meta: { name: 'Save as', group: 'File' } },
},
{
hotkey: ['G', 'H'],
callback: () => goHome(),
options: { meta: { name: 'Go home', group: 'Navigation' } },
},
])meta doesn't affect key matching. It feeds your UI lists and shows up in devtools. To add custom fields like icon, augment HotkeyMeta:
declare module '@tanstack/solid-hotkeys' {
interface HotkeyMeta {
icon?: string
}
}Pass meta inline without memoizing it. TanStack Hotkeys compares its primitive fields (string, number, boolean) to decide when cheat sheet lists should update.
Note
Don't mutate an existing meta object in place. Non-primitive fields (arrays, nested objects, JSX, or functions) don't trigger an update on their own, so if your UI renders one, change a primitive field like name or a version key alongside it.
createHotkeyRegistrations updates automatically as hotkeys register, unregister, or change scopes. Show the ones with a name:
import { For } from 'solid-js'
import {
createFormatForDisplay,
createHotkeyRegistrations,
} from '@tanstack/solid-hotkeys'
function ShortcutList() {
const formatForDisplay = createFormatForDisplay()
const registrations = createHotkeyRegistrations()
const named = () =>
registrations().filter(
(reg) => reg.options.meta?.name && reg.status === 'active',
)
return (
<dl>
<For each={named()}>
{(reg) => (
<div>
<dt>{reg.options.meta?.name}</dt>
<dd>
<kbd>{formatForDisplay(reg.hotkey)}</kbd>
</dd>
</div>
)}
</For>
</dl>
)
}Filtering by meta?.name omits unnamed helper shortcuts, such as a dialog's Escape. Checking status === 'active' hides paused shortcuts:
Each entry also includes id, hotkey, options, target, triggerCount, and trigger(). Chord entries (kind === 'chord') add parsedChord, and sequence entries (kind === 'sequence') add parsedSequence and matchedStepCount (used in Show sequences in your UI). If multiple mounted components register the same shortcut, such as rows in a list, each registration appears as its own entry.
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.
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.
createAppHotkeyList returns every app hotkey in declaration order, even when nothing has registered it yet. Each item includes its status, isCustom flag, and live registrations array, deduplicated to one row even if multiple components register the same ID:
import { For } from 'solid-js'
import { createAppHotkeyList, createFormatForDisplay } from '@tanstack/solid-hotkeys'
function CheatSheet() {
const formatForDisplay = createFormatForDisplay()
const items = createAppHotkeyList()
return (
<ul>
<For each={items()}>
{({ appHotkey, status, isCustom }) => (
<li data-status={status}>
{appHotkey.meta?.name}:{' '}
{appHotkey.hotkey ? formatForDisplay(appHotkey.hotkey) : 'Unassigned'}
{isCustom && ' (custom)'}
</li>
)}
</For>
</ul>
)
}| Status | Meaning |
|---|---|
| 'active' | At least one registration reports 'active' |
| 'suspended' | Enabled registrations exist, but none can fire: their scope is inactive, or character keys are suspended |
| 'disabled' | Registered, but every registration has enabled: false |
| 'inactive' | Has a hotkey assigned, but nothing has registered it yet |
| 'unbound' | No hotkey assigned (null) |
createAppHotkeyList needs a HotkeysProvider with appHotkeys.
If you mix declared app hotkeys with local component hotkeys, combine both lists by filtering out registrations that already have options.appHotkeyId:
const undeclared = () =>
registrations().filter(
(reg) => reg.options.appHotkeyId === undefined && reg.options.meta?.name,
)Group items by meta.group for scannable sections:
function CheatSheet() {
const items = createAppHotkeyList()
const groups = () => [
...new Set(items().map((item) => item.appHotkey.meta?.group)),
]
return (
<For each={groups()}>
{(group) => (
<section>
<h3>{group ?? 'Other'}</h3>
<ul>
<For
each={items().filter(
(item) => item.appHotkey.meta?.group === group,
)}
>
{({ appHotkey }) => <li>...</li>}
</For>
</ul>
</section>
)}
</For>
)
}To style individual keys as separate <kbd> badges, pass parts: true to the function from createFormatForDisplay. See Render individual keycaps.
Wrap your cheat sheet dialog in an exclusive scope so pressing a shortcut while reading the help list doesn't trigger actions behind the modal:
import { Show, createSignal } from 'solid-js'
import {
HotkeysProvider,
createHotkey,
createHotkeys,
useAppHotkeys,
} from '@tanstack/solid-hotkeys'
// Declared with defineAppHotkeys:
// 'help.shortcuts': { hotkey: 'Mod+/', meta: { name: 'Keyboard shortcuts', group: 'Help' } }
function App() {
const appHotkeys = useAppHotkeys()
const [isOpen, setIsOpen] = createSignal(false)
createHotkey(() => appHotkeys()['help.shortcuts'], () => setIsOpen(true))
return (
<>
<Main />
<Show when={isOpen()}>
<HotkeysProvider scope="cheat-sheet" exclusive>
<CheatSheetDialog onClose={() => setIsOpen(false)} />
</HotkeysProvider>
</Show>
</>
)
}
function CheatSheetDialog(props: { onClose: () => void }) {
const appHotkeys = useAppHotkeys()
createHotkeys(() => [
{ hotkey: 'Escape', callback: () => props.onClose() },
// Page hotkeys pause while exclusive is active, so register the toggle inside too
{ hotkey: appHotkeys()['help.shortcuts'], callback: () => props.onClose() },
])
return (
<div role="dialog" aria-label="Keyboard shortcuts">
<CheatSheet />
</div>
)
}A few details to keep in mind:
Register the toggle hotkey inside the dialog as well so pressing the same keys closes it cleanly, since exclusive suspends the outer registration.
createAppHotkeyList still lists every app hotkey while the dialog is open. Items registered outside it report 'suspended'. To let background shortcuts keep working, omit exclusive. The cheat sheet's own hotkeys still win, because its scope is newer. See Exclusive scopes.
Register the toggle hotkey inside the dialog as well so pressing the same keys closes it cleanly, since exclusive suspends the outer registration.
createAppHotkeyList still shows every app hotkey while open. Items from the page behind it report 'suspended'. To let background shortcuts keep working, omit exclusive. See Exclusive scopes.
If you bind ? to open your cheat sheet, remember single-key shortcuts need a way to turn them off or remap them for accessibility. See Single-key shortcuts need an off switch.
See the Kitchen Sink example for a complete grouped cheat sheet with live statuses and rebinding.