# ShortcutList

> 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.
- Molecule. Source: `src/components/molecules/shortcut-list/ShortcutList.tsx`
- Rendered docs page: `/components/shortcut-list`

## Import

```tsx
import { ShortcutList } from 'src/components/molecules/shortcut-list/ShortcutList'
```

Paths are from the Division DS repository root. Installed with shadcn they start `src/division-ds/` instead of `src/` (`src/division-ds/components/...`); import them relative to your file. An install has no index barrels: import each component from its own file, never from `components/molecules`.

## Props

| Prop | Type | Default | Description |
|---|---|---|---|
| `groups` | `ShortcutGroup[]` |  | 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. |
| `headingLevel` | `2 \| 3 \| 4` | `3` | The level of the group titles: 3 under a dialog title, 2 under a page title. |
| `className` | `string` |  | Merged with the root's classes. When Tailwind utility classes clash, the later one wins. |
| `ref` | `Ref<HTMLDivElement>` |  | The root div. |

## Types and helpers

Exported beside the component, from the same file. Import a type with `import type { ... }`.

```ts
export type Shortcut = {
  /** Handed to onEdit. Unique across the whole list. */
  id: string
  /** What the shortcut does: "Go to Work". */
  label: string
  /** One line more, when the label needs it. */
  description?: string
  /** Steps pressed one after another, each a chord of keys pressed together.
   *  `[['G'], ['W']]` is "G then W"; `[['Ctrl', 'K']]` is "Ctrl + K". Empty, the row says "Not set". */
  keys: string[][]
}
```

```ts
export type ShortcutGroup = {
  /** The group's heading, and its React key: unique within the list. */
  title: string
  shortcuts: Shortcut[]
}
```

## Examples

Each is compiled and rendered on the docs page. Imports are omitted; see above.

### Sequences and chords, in groups

```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

```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 />
```

## Keyboard

| Keys | Result |
|---|---|
| `Tab` | Moves through the Edit buttons, when there are any. The list itself takes no focus. |

## 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.

## Anatomy

- **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>".
