Keyboard Shortcuts
React keyboard shortcuts cheat sheet: a searchable dialog of grouped shortcuts opened with the ? key or a button, with Command glyphs on Mac and Ctrl elsewhere.
Installation
npx shadcn@latest add @minidev/keyboard-shortcuts
MiniDev UI is in the shadcn registry directory, so the short form works with no setup. Older CLI versions can use the full URL: npx shadcn@latest add https://ui.minidev.pro/r/keyboard-shortcuts.json
Usage
import { KeyboardShortcuts } from "@/components/ui/keyboard-shortcuts"
export function Example() {
return (
<KeyboardShortcuts />
)
}
API reference
| Prop | Type | Default |
|---|---|---|
| groupsShortcut groups, shown as titled columns. Defaults to a sample invoicing app. | KeyboardShortcutGroup[] | SAMPLE_GROUPS |
| titleDialog title. | string | "Keyboard shortcuts" |
| hotkeyKey that opens the sheet from anywhere on the page, outside text fields. Empty disables it. | string | "?" |
| openControlled open state. Leave undefined for internal state. | boolean | - |
| onOpenChange | (open: boolean) => void | - |
| showTriggerRender the built-in trigger button. | boolean | true |
| triggerLabelText of the built-in trigger button. | string | "Keyboard shortcuts" |
| className | string | - |
When to use
Shortcuts are grouped, filtered as you type, and written once with portable names (mod, shift, alt, enter) that render as ⌘ ⇧ ⌥ ↵ on a Mac and Ctrl, Shift, Alt, Enter elsewhere; screen readers hear the key names. The platform is read after mount, so server and client markup match. For a static, always-visible list use ShortcutCheatSheet; for one key inline use Kbd.
Keyboard interactions
| Key | Action |
|---|---|
| ? | Anywhere outside a text field, opens the sheet (or whatever key hotkey is). Shift+/ also works on layouts that report it as "/". |
| TaborShiftTab | Moves between the search field and the close button; focus stays in the dialog. |
| Escape | Closes the sheet and clears the search. |
Accessibility
- Each row has screen-reader-only key names, such as "Command K" on a Mac or "Control K" elsewhere, while the glyphs are
aria-hidden. - The search field gets focus when the sheet opens and is labelled "Search shortcuts". Searching "command" also finds ⌘ shortcuts.
- Each group is a
<section>labelled by its<h3>. The trigger hasaria-haspopup="dialog"andaria-expanded.
Frequently asked questions
How do I change or turn off the ? hotkey?
Pass hotkey with another key, or hotkey="" to turn it off. The listener ignores presses with ⌘, Ctrl or Alt held, and presses inside inputs, textareas, selects and contenteditable elements, so typing a question mark in a field does not open it.
How do I show ⌘ on Mac and Ctrl on Windows?
Write mod in keys: { keys: ["mod", "K"], label: "Command palette" } shows ⌘ K on a Mac and Ctrl K elsewhere. shift, alt, ctrl, enter, backspace, esc, tab, space, up, down, left and right are mapped too.
Does KeyboardShortcuts make the shortcuts work?
No. It only lists them. Register each shortcut in your app; the sheet is the reference people read.
Why does a Mac show Ctrl for a moment?
The platform is read with useSyncExternalStore, and the server snapshot is non-Mac, so the server HTML and the first client render show Ctrl. After hydration the client switches to ⌘, which avoids a hydration mismatch.
Dependencies
Examples
Custom groups
groups is any list of sections; keys use portable names like mod, shift and enter so the sheet shows the viewer's modifier glyphs.
Controlled from your own trigger
showTrigger false and open plus onOpenChange let a toolbar icon open the sheet; an empty hotkey leaves the global key to your app.