Molecules · Shortcut list
Shortcut list
Keyboard shortcuts in named groups. Each row is a label and its keys as Kbd caps: "G then W" for keys pressed one after another, "Ctrl + K" for keys pressed together. With onEdit, every row gets an Edit button, for a settings page where shortcuts can be changed.
- Best for
- Listing an app’s shortcuts, in a help overlay or on a settings page.
- Not for
- One shortcut beside its action: use Kbd.
This page as Markdown, a plain-text copy for a coding agent (an AI tool that writes code).
Examples
Sequences and chords, in groups
Go to
- Work
- G then W
- Agents
- G then A
- Docs
- Project notes, specs and commands
- G then D
Anywhere
- Open the command palette
- Ctrl + K
- Open the chat
- Ctrl + Shift + L
- Show these shortcuts
- ?
Code
tsx
const GROUPS: ShortcutListProps['groups'] = [ { title: 'Go to', shortcuts: [ { id: 'go-work', label: 'Work', keys: [['G'], ['W']] }, { id: 'go-agents', label: 'Agents', keys: [['G'], ['A']] }, { id: 'go-docs', label: 'Docs', description: 'Project notes, specs and commands', keys: [['G'], ['D']] }, ], }, { title: 'Anywhere', shortcuts: [ { id: 'palette', label: 'Open the command palette', keys: [['Ctrl', 'K']] }, { id: 'chat', label: 'Open the chat', keys: [['Ctrl', 'Shift', 'L']] }, { id: 'help', label: 'Show these shortcuts', keys: [['?']] }, ], },]<ShortcutList groups={GROUPS} className="w-full max-w-xl" />With onEdit: an Edit button on every row
Go to
- Work
- G then W
- Agents
- G then A
- Docs
- Project notes, specs and commands
- G then D
Anywhere
- Open the command palette
- Ctrl + K
- Open the chat
- Ctrl + Shift + L
- Show these shortcuts
- ?
Code
tsx
const GROUPS: ShortcutListProps['groups'] = [ { title: 'Go to', shortcuts: [ { id: 'go-work', label: 'Work', keys: [['G'], ['W']] }, { id: 'go-agents', label: 'Agents', keys: [['G'], ['A']] }, { id: 'go-docs', label: 'Docs', description: 'Project notes, specs and commands', keys: [['G'], ['D']] }, ], }, { title: 'Anywhere', shortcuts: [ { id: 'palette', label: 'Open the command palette', keys: [['Ctrl', 'K']] }, { id: 'chat', label: 'Open the chat', keys: [['Ctrl', 'Shift', 'L']] }, { id: 'help', label: 'Show these shortcuts', keys: [['?']] }, ], },]function EditableExample() { const [editing, setEditing] = useState<string | null>(null) const label = GROUPS.flatMap(group => group.shortcuts).find(shortcut => shortcut.id === editing)?.label return ( <div className="flex flex-col gap-3 w-full max-w-xl"> <ShortcutList groups={GROUPS} onEdit={setEditing} /> <p role="status" className="min-h-6 text-sm text-[var(--color-text-secondary)]"> {label ? `Press the new keys for “${label}”.` : ''} </p> </div> )}<EditableExample />Anatomy
| Part | What it is |
|---|---|
| Group title | A heading (h3 by default) in the label role: mono, uppercase, 11px, text.secondary. |
| List | One dl per group. Each row is a div holding a dt and its dd elements, with a hairline above it. |
| Label | The dt, body text in text.primary. An optional description sits under it in text.secondary, as a second dd. |
| Keys | A dd on the right: a Kbd per key, "+" between keys pressed together and "then" between steps, both as real text. With no keys, "Not set" in text.secondary. |
| Edit button | With onEdit, a small ghost Button after the keys, named "Edit shortcut for <label>". |
Props
- groupsShortcutGroup[]
- Required. The groups in order. Each group has title (its heading, unique within the list) and shortcuts. Each shortcut has id (unique across the list; onEdit gets it), label (what it does: "Go to Work"), keys and, optionally, description (one more line under the label). keys is a list of steps, each a chord of keys pressed together: [['G'], ['W']] is G then W, [['Ctrl', 'K']] is Ctrl + K, and an empty list shows 'Not set' in text.secondary.
- onEdit(id: string) => void
- Adds an Edit button to every row. Open your own key recorder from it, and pass back the new keys.
- headingLevel2 | 3 | 4Default 3
- The level of the group titles: 3 under a dialog title, 2 under a page title.
- classNamestring
- Merged with the root's classes. When Tailwind utility classes clash, the later one wins.
- refRef<HTMLDivElement>
- The root div.
Keyboard
| Keys | Result |
|---|---|
| Tab | Moves through the Edit buttons, when there are any. The list itself takes no focus. |
Do and don't
Do
- Write each key the way the keyboard prints it: Ctrl, Shift, Esc, K.
- Group by where the shortcut works or what it does: "Go to", "Anywhere", "In a list".
- Set headingLevel to fit the page: 3 inside a Dialog, 2 under a PageHeader.
Don't
- Don't put a whole chord in one key string (['Ctrl+K']). Give each key its own entry, so each gets a cap.
- Don't list shortcuts that only work on another screen without saying where, in the group title or the description.