- Add the registry
- Add kbd
Usage
Screen readers don't read symbols like ⌘ reliably, so also set aria-keyshortcuts on the control
the shortcut triggers.
Composition
Examples
Shortcuts
KbdGroup holds the keys of one shortcut.
On a raised surface
Small
size="sm" fits hints and tooltips.
In text
Press ⌘K to open the command menu.
In a tooltip
Show an icon button's shortcut in its tooltip.
Platform shortcuts
useShortcutDisplay, from the use-shortcut hook, shows a chord the way the reader's platform writes it, such as ⌘ K on a
Mac and Ctrl K elsewhere. It takes a TanStack Hotkeys chord,
where Mod is ⌘ on a Mac and Ctrl elsewhere, and returns keys, one label per key for a
KbdGroup, and label, the keys joined for a single Kbd: ⌘K on a Mac and Ctrl+K elsewhere.
The same file exports ShortcutChord, the type of a chord, and useShortcut, which runs a
callback when a chord is pressed: TanStack Hotkeys'
useHotkey,
renamed.
- Search
- Command palette
- Move line up
The server can't tell the reader's platform, so the hook returns null until the page hydrates,
and the example shows no keys until then rather than guessing and correcting itself. The
Command menu uses both hooks to show and bind its items' shortcuts.
To add the hook on its own: