# Shortcut sheet

> A searchable keyboard shortcuts reference and modal with live physical keycap lighting, chord and sequence matching and OS-aware glyphs.

Static help tables tell users what a shortcut is without letting them feel it. ShortcutSheet pairs directly with ShortcutRecorder using the same canonical syntax ("mod+k", "mod+shift+f", "g then i", "/"), automatically rendering macOS (⌘ ⌥ ⇧ ⌃) or Windows/Linux (Ctrl Alt Shift) keycaps. While the sheet is open, pressing any physical key on your keyboard depresses and illuminates every matching keycap across the two-column hairline grid; completing a chord or two-key sequence highlights that exact command row with an emerald Ready badge and optional onTrigger callback. Use variant="inline" inside settings or help pages, or variant="dialog" with a built-in global "?" hotkey toggle.

## Install

```bash
npx shadcn@latest add https://hairlineui.com/r/shortcut-sheet.json
```

Needs React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.

- npm: `lucide-react`
- Hairline UI components it needs (the CLI installs them too): `text-morph`, `number-roll`
- Docs and live preview: https://hairlineui.com/ui/shortcut-sheet
- Registry item (source): https://hairlineui.com/r/shortcut-sheet.json

## Usage

```tsx
import { ShortcutSheet } from "@/components/shortcut-sheet";

<ShortcutSheet
  variant="dialog"
  groups={[
    {
      title: "General",
      items: [
        { id: "cmd", label: "Open command menu", keys: "mod+k" },
        { id: "inbox", label: "Go to Inbox", keys: "g then i" },
      ],
    },
  ]}
/>
```

## Global "?" keyboard overlay mounted in your app shell

Mount ShortcutSheet once in your workspace layout so pressing "?" opens the live reference from any non-input surface.

```tsx
"use client";
import { ShortcutSheet, type ShortcutGroup } from "@/components/shortcut-sheet";

const GROUPS: ShortcutGroup[] = [
  {
    title: "Navigation",
    items: [
      { id: "cmd", label: "Command menu", keys: "mod+k" },
      { id: "inbox", label: "Go to Inbox", keys: "g then i" },
    ],
  },
];

export function WorkspaceShortcutOverlay() {
  return <ShortcutSheet variant="dialog" hotkey="?" groups={GROUPS} />;
}
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `groups` | `ShortcutGroup[]` | – | Array of { title, items: [{ id, label, keys, description?, keywords? }] }. |
| `variant` | `"inline" \| "dialog"` | `"inline"` | Render as an embedded card or a global-hotkey modal overlay. |
| `open / defaultOpen / onOpenChange / hotkey` | `boolean / boolean / fn / string \| null` | `— / false / — / "?"` | Dialog visibility state and global toggle key (pass null to disable global listener). |
| `liveKeys / onTrigger` | `boolean / (entry: ShortcutEntry) => void` | `true / —` | Enable real-time physical keycap lighting and chord/sequence completion callback. |
| `platform / searchable / title / sound` | `"auto" \| "mac" \| "other" / boolean / string / boolean` | `"auto" / true / "Keyboard shortcuts" / false` | OS glyph mode, search bar toggle, header title and opt-in Web Audio ticks. |

## States

- **idle grid**: Grouped two-column hairline cards with raised physical <kbd> keycaps and a live status pill.
- **key pressed**: Matching <kbd> keycaps physically depress 1px and invert to foreground ink while held.
- **chord or sequence matched**: Completing a binding tints the command row emerald, flashes a Ready chip and fires onTrigger.
- **filtered**: Typing in the search bar narrows groups live and removes empty sections cleanly.
- **dialog overlay**: Toggled globally by "?" (customisable via hotkey), with Escape and outside-click dismissal.

## What it handles

A great shortcuts overlay stays out of the way until "?" is pressed, adapts to the user OS and confirms real keypresses immediately.

- **Live physical keycap lighting**: Pressing real keys depresses and highlights every matching <kbd> cap across the grid in real time.
- **Chord and two-key sequence matching**: Supports both simultaneous chords ("mod+shift+f") and timed sequences ("g then i"), lighting up the matched row with an emerald Ready chip.
- **Automatic OS glyph adaptation**: Detects macOS vs Windows/Linux safely with useSyncExternalStore (zero hydration mismatch) or accepts an explicit platform override.
- **Built-in global "?" dialog toggle**: variant="dialog" listens safely for "?" outside text inputs and closes on Escape or backdrop click with zero external modal packages.
- **Instant command and key filtering**: Search by section title, command label, description, canonical key spec or custom keywords.
- **Shared canonical syntax with ShortcutRecorder**: Uses identical string specs ("mod+k", "g then p", "esc") and exports parseShortcutSpec() for reuse.

## Replaces

static shortcut help table, global "?" modal listener, macOS vs Windows kbd mapper, two-key sequence matcher

## Where it fits

- **Power-user SaaS workspaces**: Attach variant="dialog" at your app shell so pressing "?" opens a searchable shortcut overlay with live keycap testing.
- **Settings and help pages**: Embed variant="inline" alongside ShortcutRecorder to document built-in navigation sequences and global chords.
- **Interactive onboarding**: Wire onTrigger to let new users practice real chords ("⌘ K", "G then I") right inside the cheatsheet.
- **Canvas and code editors**: Group dozens of editor, view and formatting bindings into clean two-column sections with instant keyword filtering.

## Notes

- Global "?" and live keycap listeners ignore events originating inside inputs, textareas, selects and contentEditable regions.
- OS detection uses useSyncExternalStore with a deterministic "mac" server snapshot to guarantee clean SSR hydration.
- Under prefers-reduced-motion: reduce, keycaps switch state cleanly without transform transitions.

License: MIT (https://hairlineui.com/license#components)
