<!-- generated by scripts/gen-docs.mjs from docs/system/command-palette.md. Edit the source and rerun. -->
# CommandPalette

## Description
Jumps to any record or runs any command from one search field, opened from anywhere with Command K or Control K.

`import { CommandPalette, CommandPaletteTrigger, CommandPaletteContent, CommandPaletteInput, CommandPaletteList, CommandPaletteGroup, CommandPaletteGroupLabel, CommandPaletteCollection, CommandPaletteItem, CommandPaletteItemDescription, CommandPaletteItemHint, CommandPaletteMatch, CommandPaletteEmpty, CommandPaletteStatus, CommandPaletteFooter, CommandPaletteShortcutHint } from "@/components/cobalt/ui/command-palette"`, source `registry/cobalt/ui/command-palette.tsx`, status `ready-with-gaps`.
Foundation: `Base UI Dialog with Base UI Autocomplete inline`. Traps checked: `trap/color-only-status`, `trap/focus-ring-shape`, `trap/overlay-title`, `trap/overlay-focus-return`, `trap/overlay-conditional-render`, `trap/overlay-no-max-height`, `trap/escape-nested`, `trap/exit-eats-input`, `trap/motion-origin`, `trap/scroll-chain`, `trap/select-async`, `trap/live-region-double`, `trap/menu-only-path`, `trap/touch-autofocus`, `trap/viewport-height`, `trap/motion-frequent`.

Where each trap is answered: `trap/overlay-title`, the window is named by `label` on `CommandPaletteContent`; `trap/overlay-focus-return` in Keyboard, focus goes back to the trigger after Enter or Escape (measured); `trap/overlay-conditional-render`, the host keeps the palette mounted and drives `open`; `trap/overlay-no-max-height`, the window is at most the screen less the gutters and its list scrolls between the field and the key hints; `trap/escape-nested`, Escape reaches the autocomplete first, whose close is bound to the window's; `trap/exit-eats-input`, the backdrop and window take no input while they fade out, from Base UI; `trap/motion-origin` in Motion, the window fades in place with nothing to grow from; `trap/scroll-chain`, the list is `overscroll-contain`; `trap/select-async` in `rule/command-palette-async-waits`; `trap/live-region-double`, Empty and Status are the only live regions; `trap/menu-only-path` in `rule/command-palette-not-the-only-path`; `trap/touch-autofocus`, the field takes focus only when the person opens the window; `trap/viewport-height`, the height reads `100dvh`; `trap/motion-frequent` in Motion, the window opens many times a day: from the shortcut it appears and goes at once, and from the trigger it only fades. `trap/color-only-status` by the underline under each matched word, beside its accent ink (Tokens). `trap/focus-ring-shape` by the field's edge and ring on the trigger after Tab, through `trackFocusSource` (States).

### Foundation
| Given by the foundation | Added by the team |
|---|---|
| Base UI `Dialog`: a modal popup with focus moved in, kept in and returned, Escape and an outside press to close; Base UI `Autocomplete` with `inline` and `open`: an input with `role="combobox"` over a `listbox` it filters, flat or grouped `items`, the highlight on the arrows and the pointer, Enter to run the highlighted item, `Empty` and `Status` live regions | `CommandPalette` holds `open` and listens for Command K or Control K (`shortcut`, or `false`); the window 16px from the top on a phone and 96px from 640px up, up to 576px wide, at `--r-3xl` with `--shadow-floating`, fading with `dialog-motion` over the shared `Overlay` when the trigger opens it, and appearing and going at once, scrim included, when Command K opens it; the page behind it inert (`useCobaltModal`); the field row with a 20px search glyph, in line with the rows' glyphs, and an Esc key that closes; the glyph turning into a spinning one in the same slot while a slower search runs, so the wait shows without a row that comes and goes (`registry/cobalt/ui/command-palette.tsx:340-343`); the window holding the tallest height it has had since it opened, so narrowing the results never moves its bottom edge and the field never moves, and growing on the layout spring when content needs more room (`registry/cobalt/ui/command-palette.tsx:192`); rows 38px at `--r-lg` inside `--pad-popup`, concentric with the window's `--r-3xl`, with a glyph first and a hint last, two lines when a row has `CommandPaletteItemDescription`, and the Enter glyph at the end of the highlighted row in a slot every row keeps, hidden under a coarse pointer; `CommandPaletteMatch`, which marks the typed words in a row with `mark`; the first row highlighted as it opens, so Enter runs it; `closeOnClick` closes the window after a row runs; a disabled row skips the highlight under the pointer and keeps the pointer, so a double-click on it selects nothing behind it (`registry/cobalt/ui/command-palette.tsx:442-443`); the second click of the double-click that opened the window dropped, so it runs no row (`guardOpeningClick`); `busy` and `CommandPaletteStatus` for a server search; the key hints in the footer, Arrow keys and Enter, with Esc left to the button at the end of the field so it is shown once, and the footer left out under a coarse pointer; the trigger as a field look-alike with the platform's shortcut through `Kbd` from `registry/cobalt/ui/kbd.tsx`, drawing the field's edge and ring after Tab |

## Examples
Command K opens it: recent records first, then advisers, funds and commands that narrow as you type, with the typed words marked.

Real uses, 0 call sites (`rg -n "<CommandPalette\b" app registry --glob '!registry/cobalt/ui/*'`): the showcase's top bar has none; Atlas built one by hand (`docs/research/2026-10-17-coverage.md`, row 12).

### Example files
| File | Covers | Caption |
|---|---|---|
| `docs/system/examples/command-palette/default.tsx` | default | Recent records, then groups that narrow as you type, with the typed words marked |
| `docs/system/examples/command-palette/async.tsx` | filter=null | A server search that waits for two letters and a pause in typing, keeps the last results and dims them past 250ms; each row has a second line |
| `docs/system/examples/command-palette/error.tsx` | state:error | When the search fails, the window says so where the results were and offers Retry |
| Not applicable: open default.tsx with an empty field | state:recent | The Recent group first |
| Not applicable: type a word nothing has in default.tsx | state:empty | The Empty sentence |
| Not applicable: type in async.tsx | state:loading | The old rows dimmed and the field's glyph spinning past 250ms, "Searching" read aloud |
| Not applicable: arrow or point at any row | state:highlighted | The grey fill on one row |
| Not applicable: press Command K or Control K on any page with a palette | state:open | The window near the top, focus in the field |
| `docs/system/examples/command-palette/in-section.tsx` | composition:Section | Opened from a section's controls with a Button |

Example: Recent records, then groups that narrow as you type, with the typed words marked (`docs/system/examples/command-palette/default.tsx`)

```tsx
import { useState } from "react";

import { ClockIcon, LayoutGridIcon, SearchIcon, UserIcon } from "@/components/cobalt/icon";
import {
  CommandPalette,
  CommandPaletteCollection,
  CommandPaletteContent,
  CommandPaletteEmpty,
  CommandPaletteFooter,
  CommandPaletteGroup,
  CommandPaletteGroupLabel,
  CommandPaletteInput,
  CommandPaletteItem,
  CommandPaletteItemHint,
  CommandPaletteList,
  CommandPaletteMatch,
  CommandPaletteTrigger,
} from "@/components/cobalt/ui/command-palette";

type Entry = { value: string; label: string; hint: string; kind: "recent" | "adviser" | "fund" | "command" };
type Group = { value: string; items: Entry[] };

const entry = (kind: Entry["kind"], label: string, hint: string): Entry => ({
  value: `${kind}:${label}`,
  label,
  hint,
  kind,
});

const recent = [entry("recent", "Harbour Lane Capital", "Adviser"), entry("recent", "Alder Point Income Fund", "Fund")];
const groups: Group[] = [
  {
    value: "Advisers",
    items: [
      entry("adviser", "Alder Point Capital", "Boston"),
      entry("adviser", "Birchwood Partners", "Chicago"),
      entry("adviser", "Harbour Lane Capital", "New York"),
      entry("adviser", "Juniper Ridge Advisers", "Phoenix"),
    ],
  },
  {
    value: "Funds",
    items: [
      entry("fund", "Alder Point Income Fund", "$1.2B"),
      entry("fund", "Birchwood Growth Partners II", "$640M"),
      entry("fund", "Harbour Lane Credit Opportunities", "$2.9B"),
    ],
  },
  {
    value: "Commands",
    items: [entry("command", "Open the screener", "Page"), entry("command", "Export watchlist as CSV", "File")],
  },
];

const glyph = { recent: ClockIcon, adviser: UserIcon, fund: LayoutGridIcon, command: SearchIcon };

export default function Example() {
  const [query, setQuery] = useState("");
  const [opened, setOpened] = useState<string | null>(null);
  // Recent records only while the field is empty; once you type, every match comes from the full lists.
  const items: Group[] = query.trim() === "" ? [{ value: "Recent", items: recent }, ...groups] : groups;
  return (
    <div className="flex flex-col items-start gap-3">
      <CommandPalette onOpenChange={(open) => open && setQuery("")}>
        <CommandPaletteTrigger className="w-72" label="Search advisers and funds" />
        <CommandPaletteContent items={items} value={query} onValueChange={setQuery} label="Search advisers, funds and commands">
          <CommandPaletteInput placeholder="Search advisers, funds and commands" />
          <CommandPaletteEmpty>Nothing matches “{query}”. Try a firm name or a city.</CommandPaletteEmpty>
          <CommandPaletteList>
            {(group: Group) => (
              <CommandPaletteGroup key={group.value} items={group.items}>
                <CommandPaletteGroupLabel>{group.value}</CommandPaletteGroupLabel>
                <CommandPaletteCollection>
                  {(item: Entry) => {
                    const Glyph = glyph[item.kind];
                    return (
                      <CommandPaletteItem key={item.value} value={item} onClick={() => setOpened(item.label)}>
                        <Glyph aria-hidden="true" />
                        <span className="min-w-0 flex-1">
                          <CommandPaletteMatch text={item.label} query={query} />
                        </span>
                        <CommandPaletteItemHint>{item.hint}</CommandPaletteItemHint>
                      </CommandPaletteItem>
                    );
                  }}
                </CommandPaletteCollection>
              </CommandPaletteGroup>
            )}
          </CommandPaletteList>
          <CommandPaletteFooter />
        </CommandPaletteContent>
      </CommandPalette>
      <p className="text-sm text-muted-foreground" aria-live="polite">
        {opened === null ? "Nothing opened yet." : `Opened ${opened}.`}
      </p>
    </div>
  );
}
```

Example: Opened from a section's controls with a Button (`docs/system/examples/command-palette/in-section.tsx`)

```tsx
import { useState } from "react";

import { SearchIcon } from "@/components/cobalt/icon";
import { Button } from "@/components/cobalt/ui/button";
import {
  CommandPalette,
  CommandPaletteContent,
  CommandPaletteEmpty,
  CommandPaletteInput,
  CommandPaletteItem,
  CommandPaletteItemHint,
  CommandPaletteList,
  CommandPaletteTrigger,
} from "@/components/cobalt/ui/command-palette";
import { Section } from "@/components/cobalt/ui/section";

type Stay = { value: string; label: string; city: string };

const stays: Stay[] = [
  { value: "loft", label: "Harbour loft", city: "Lisbon" },
  { value: "cabin", label: "Pine cabin", city: "Bergen" },
  { value: "flat", label: "Garden flat", city: "Porto" },
  { value: "studio", label: "Canal studio", city: "Amsterdam" },
];

export default function Example() {
  const [shown, setShown] = useState<string>("loft");
  return (
    <Section
      id="your-stays"
      heading="Your stays"
      className="w-full max-w-lg"
      controls={
        <CommandPalette shortcut={false}>
          <CommandPaletteTrigger render={<Button variant="secondary" size="sm" />}>
            <SearchIcon aria-hidden="true" />
            Find a stay
          </CommandPaletteTrigger>
          <CommandPaletteContent items={stays} label="Find a stay">
            <CommandPaletteInput placeholder="Search your stays" />
            <CommandPaletteEmpty>None of your stays matches.</CommandPaletteEmpty>
            <CommandPaletteList>
              {(stay: Stay) => (
                <CommandPaletteItem key={stay.value} value={stay} onClick={() => setShown(stay.value)}>
                  <span className="min-w-0 flex-1">{stay.label}</span>
                  <CommandPaletteItemHint>{stay.city}</CommandPaletteItemHint>
                </CommandPaletteItem>
              )}
            </CommandPaletteList>
          </CommandPaletteContent>
        </CommandPalette>
      }
    >
      <ul className="flex flex-col">
        {stays.map((stay) => (
          <li
            key={stay.value}
            aria-current={stay.value === shown || undefined}
            className="flex min-h-10 items-center justify-between rounded-xl px-2.5 text-sm aria-current:bg-muted"
          >
            <span>{stay.label}</span>
            <span className="text-muted-foreground">{stay.city}</span>
          </li>
        ))}
      </ul>
    </Section>
  );
}
```

## Variants
Not applicable: one window. The trigger's look is the field look-alike by default or any control through `render`, and a server search is `filter={null}`; both are in the example files.

Example: A server search that waits for two letters and a pause in typing, keeps the last results and dims them past 250ms; each row has a second line (`docs/system/examples/command-palette/async.tsx`)

```tsx
import { useEffect, useState } from "react";

import { UserIcon } from "@/components/cobalt/icon";
import {
  CommandPalette,
  CommandPaletteContent,
  CommandPaletteEmpty,
  CommandPaletteFooter,
  CommandPaletteInput,
  CommandPaletteItem,
  CommandPaletteItemDescription,
  CommandPaletteItemHint,
  CommandPaletteList,
  CommandPaletteMatch,
  CommandPaletteStatus,
  CommandPaletteTrigger,
} from "@/components/cobalt/ui/command-palette";
import { useSlowWait } from "@/lib/cobalt/use-slow-wait";

type Person = { value: string; label: string; firm: string; city: string };

const people: Person[] = (
  [
    ["Amara Nwosu", "Alder Point Capital", "Boston"],
    ["Ben Halvorsen", "Birchwood Partners", "Chicago"],
    ["Carmen Ruiz", "Cedar Row Advisers", "Miami"],
    ["Daniel Mercer", "Harbour Lane Capital", "New York"],
    ["Elena Rossi", "Juniper Ridge Advisers", "Phoenix"],
    ["Felix Laurent", "Kestrel Hill Partners", "Denver"],
    ["Grace Tan", "Larch Street Capital", "Seattle"],
    ["Hiro Sato", "Meadowbrook Advisers", "San Francisco"],
  ] as [string, string, string][]
).map(([label, firm, city]) => ({ value: label.toLowerCase().replace(/\s+/g, "-"), label, firm, city }));

// Stands in for your search endpoint: it answers in 200 to 900ms.
function search(query: string): Promise<Person[]> {
  const q = query.trim().toLowerCase();
  const found = people.filter((p) => `${p.label} ${p.firm}`.toLowerCase().includes(q));
  return new Promise((resolve) => setTimeout(() => resolve(found), 200 + Math.random() * 700));
}

// One letter matches nearly everyone, so the server is asked from two; until then the list shows
// everyone you can reach. A request waits for 150ms without a keystroke, so typing a name sends one.
const MIN_LETTERS = 2;
const DEBOUNCE_MS = 150;

export default function Example() {
  const [query, setQuery] = useState("");
  const [results, setResults] = useState<Person[]>(people);
  const [pending, setPending] = useState(false);
  const [opened, setOpened] = useState<string | null>(null);
  const slow = useSlowWait(pending);
  const asked = query.trim().length >= MIN_LETTERS;
  useEffect(() => {
    if (!asked) {
      setResults(people);
      setPending(false);
      return;
    }
    let current = true;
    setPending(true);
    const timer = setTimeout(() => {
      void search(query).then((found) => {
        if (!current) return;
        setResults(found);
        setPending(false);
      });
    }, DEBOUNCE_MS);
    return () => {
      current = false;
      clearTimeout(timer);
    };
  }, [query, asked]);
  return (
    <div className="flex flex-col items-start gap-3">
      <CommandPalette shortcut={false} onOpenChange={(open) => open && setQuery("")}>
        <CommandPaletteTrigger className="w-64" label="Search people" />
        <CommandPaletteContent items={results} filter={null} value={query} onValueChange={setQuery} label="Search people">
          <CommandPaletteInput placeholder="Search people by name or firm" />
          <CommandPaletteStatus busy={slow}>{slow ? "Searching" : null}</CommandPaletteStatus>
          <CommandPaletteEmpty>{pending ? null : `Nobody named “${query}” works at a firm we cover.`}</CommandPaletteEmpty>
          <CommandPaletteList busy={slow}>
            {(person: Person) => (
              <CommandPaletteItem key={person.value} value={person} onClick={() => setOpened(person.label)}>
                <UserIcon aria-hidden="true" />
                <span className="flex min-w-0 flex-1 flex-col">
                  <span className="truncate">
                    <CommandPaletteMatch text={person.label} query={asked ? query : ""} />
                  </span>
                  <CommandPaletteItemDescription>
                    <CommandPaletteMatch text={person.firm} query={asked ? query : ""} />
                  </CommandPaletteItemDescription>
                </span>
                <CommandPaletteItemHint>{person.city}</CommandPaletteItemHint>
              </CommandPaletteItem>
            )}
          </CommandPaletteList>
          <CommandPaletteFooter />
        </CommandPaletteContent>
      </CommandPalette>
      <p className="text-sm text-muted-foreground" aria-live="polite">
        {opened === null ? "Nobody opened yet." : `Opened ${opened}.`}
      </p>
    </div>
  );
}
```

## States
| State | Trigger | What the user can do | Shown by, besides color | Checked by |
|---|---|---|---|---|
| closed | at rest | press the trigger, or Command K or Control K | the trigger, `aria-expanded="false"` | test |
| focus-visible | Tab onto the field look-alike trigger | open it with Enter or Space | the field's accent edge and soft ring, as on every field (D40) | by hand |
| open | the trigger or the shortcut | type, arrow, run with Enter, close with Escape | the window near the top over the scrim; focus in the field; the page behind inert | by hand |
| recent | the field is empty, when the host passes a Recent group | run a recent record | the Recent group above the rest | by hand |
| highlighted | as it opens, the arrows, or the pointer | run it with Enter | the grey fill, the Enter glyph at its end, `aria-activedescendant` on the field | by hand |
| empty | nothing matches | change the text | the Empty sentence where the rows were, read politely, in the window's held height | by hand |
| loading | a server search past 250ms | keep typing | the rows dimmed to 55 percent and the field's search glyph turned into a spinning one; "Searching" is read aloud and not shown, so nothing moves | by hand |
| error | the server search failed | press Retry, or change the text | a sentence where the results were, read politely, and a Retry button | by hand |
| matched | the field holds text a row contains, through `CommandPaletteMatch` | read why the row matched | each typed word underlined in the accent ink, in a `mark` | test |
| closing | Escape, the scrim, a row run, or the shortcut again | nothing until it is gone | the fade out; focus back on the trigger | by hand |

Example: When the search fails, the window says so where the results were and offers Retry (`docs/system/examples/command-palette/error.tsx`)

```tsx
import { useCallback, useEffect, useState } from "react";

import { LayoutGridIcon } from "@/components/cobalt/icon";
import { Button } from "@/components/cobalt/ui/button";
import {
  CommandPalette,
  CommandPaletteContent,
  CommandPaletteFooter,
  CommandPaletteInput,
  CommandPaletteItem,
  CommandPaletteList,
  CommandPaletteMatch,
  CommandPaletteStatus,
  CommandPaletteTrigger,
} from "@/components/cobalt/ui/command-palette";
import type { Status } from "@/lib/cobalt/status";

type Fund = { value: string; label: string };

// Stands in for a search endpoint that is down: it refuses after 400ms, every time.
const search = (_query: string) =>
  new Promise<Fund[]>((_, reject) => setTimeout(() => reject(new Error("unavailable")), 400));

export default function Example() {
  const [query, setQuery] = useState("");
  const [results, setResults] = useState<Fund[]>([]);
  const [status, setStatus] = useState<Status>("idle");
  const run = useCallback((q: string) => {
    setStatus("pending");
    search(q).then(
      (found) => {
        setResults(found);
        setStatus("success");
      },
      () => setStatus("failure"),
    );
  }, []);
  useEffect(() => {
    if (query.trim().length < 2) return;
    const timer = setTimeout(() => run(query), 150);
    return () => clearTimeout(timer);
  }, [query, run]);
  return (
    <CommandPalette shortcut={false} onOpenChange={(open) => open && setQuery("")}>
      <CommandPaletteTrigger className="w-64" label="Search funds" />
      <CommandPaletteContent items={results} filter={null} value={query} onValueChange={setQuery} label="Search funds">
        <CommandPaletteInput placeholder="Search funds by name" />
        <CommandPaletteStatus>
          {status === "failure" ? (
            <span className="flex w-full flex-wrap items-center justify-between gap-x-3 gap-y-1">
              Search is unavailable. Check your connection and try again.
              <Button variant="secondary" size="sm" onClick={() => run(query)}>
                Retry
              </Button>
            </span>
          ) : query.trim().length < 2 ? (
            "Type two letters of a fund's name."
          ) : null}
        </CommandPaletteStatus>
        <CommandPaletteList>
          {(fund: Fund) => (
            <CommandPaletteItem key={fund.value} value={fund}>
              <LayoutGridIcon aria-hidden="true" />
              <span className="min-w-0 flex-1 truncate">
                <CommandPaletteMatch text={fund.label} query={query} />
              </span>
            </CommandPaletteItem>
          )}
        </CommandPaletteList>
        <CommandPaletteFooter />
      </CommandPaletteContent>
    </CommandPalette>
  );
}
```

### State precedence
- Loading and empty: loading wins. While a search runs the host passes no Empty sentence and keeps the old rows.
- Error and loading: error wins. The host shows the sentence and Retry until a new search starts.
- Recent and typing: typing wins. The host drops the Recent group once the field holds text, so each record shows once.
- Highlighted and hover: the pointer wins. Moving the pointer moves the highlight to the row under it, unless that row is disabled.
- Fewer results and the window's height: the height wins. The window keeps the tallest height it has had since it opened, the rows at the top and room under them; measured 0px of change across typing in every example at 1440 and 390, against a 188px drop in one frame before (`.design-system/evidence/command-palette/height-1440-and-390.json`).
- Open and the page behind: open wins. The page is inert until the window closes.
- Closed and loading: Not applicable: a closed palette searches nothing.

### Motion
| Trigger | Kind | Preset | Properties | Reduced motion |
|---|---|---|---|---|
| closed to open, from the trigger | announce | `dialog-motion`, `--t-arrive` on `--curve`, a fade in place | opacity | the fade stays; nothing moves |
| open to closed, after the trigger opened it | announce | `dialog-motion` at 70 percent of `--t-arrive` | opacity | the same |
| the scrim, after the trigger | announce | `overlay-motion`, `--t-arrive` | opacity | the same |
| open and closed with Command K or Control K, and every close after it | input | none: `data-instant` sets `transition-none` and the scrim's `--overlay-duration` to 0ms | none | the same; nothing moves |
| the Enter glyph following the highlight | input | none, it shows at once with the grey fill | opacity | the same |
| rows dimming while busy | announce | `duration-fade` | opacity | the same |
| the field's glyph while busy | announce | `IconSwap`: the search glyph and the spinning one trade places in one slot over `--t-icon` | opacity, filter | the spin stops; the swap stays |
| the window's height as content needs more | announce | the layout spring, from the height it holds | height | set at once |

## Props

<!-- Props generated from registry/cobalt/ui/command-palette.tsx with TypeScript by scripts/props-table.mjs -->
### CommandPalette

| Prop | Type | Default | Purpose |
|---|---|---|---|
| `children` | `ReactNode` |  |  |
| `defaultOpen?` | `boolean` | `false` |  |
| `onOpenChange?` | `(open: boolean) => void` |  |  |
| `open?` | `boolean` |  |  |
| `shortcut?` | `string \| false` | `"k"` | The letter that opens it with Command or Control held, or `false` for none. |

### CommandPaletteCollection

No props of its own.

### CommandPaletteContent

| Prop | Type | Default | Purpose |
|---|---|---|---|
| `children` | `ReactNode` |  |  |
| `items` | `readonly Item[] \| readonly Group<Item>[]` |  |  |
| `className?` | `string` |  |  |
| `defaultValue?` | `string` |  |  |
| `filter?` | `((item: Item, query: string) => boolean)` |  |  |
| `label?` | `string` | `"Search"` | The window's name, read as it opens. |
| `onValueChange?` | `(value: string) => void` |  |  |
| `value?` | `string` |  | The text in the search field. |

### CommandPaletteEmpty

No props of its own.

Also accepts every native `<div>` attribute; from Base UI: `render`.

### CommandPaletteFooter

| Prop | Type | Default | Purpose |
|---|---|---|---|
| `labels?` | `Partial<{ move: string; open: string; }>` |  |  |

Also accepts every native `<div>` attribute.

### CommandPaletteGroup

No props of its own.

Also accepts every native `<div>` attribute; from Base UI: `items`, `render`.

### CommandPaletteGroupLabel

No props of its own.

Also accepts every native `<div>` attribute; from Base UI: `render`.

### CommandPaletteInput

| Prop | Type | Default | Purpose |
|---|---|---|---|
| `closeLabel?` | `string` | `"Close"` | The Esc button's accessible name. |

Also accepts every native `<input>` attribute; from Base UI: `disabled`, `render`.

### CommandPaletteItem

| Prop | Type | Default | Purpose |
|---|---|---|---|
| `closeOnClick?` | `boolean` | `true` | Closes the palette after `onClick` runs. |

Also accepts every native `<div>` attribute; from Base UI: `disabled`, `index`, `nativeButton`, `onClick`, `render`, `value`.

### CommandPaletteItemDescription

No props of its own.

Also accepts every native `<span>` attribute.

### CommandPaletteItemHint

No props of its own.

Also accepts every native `<span>` attribute.

### CommandPaletteList

| Prop | Type | Default | Purpose |
|---|---|---|---|
| `busy?` | `boolean` | `false` |  |

Also accepts every native `<div>` attribute; from Base UI: `render`.

### CommandPaletteMatch

| Prop | Type | Default | Purpose |
|---|---|---|---|
| `query` | `string` |  |  |
| `text` | `string` |  |  |

### CommandPaletteShortcutHint

| Prop | Type | Default | Purpose |
|---|---|---|---|
| `letter?` | `string` | `"K"` |  |

Also accepts every native HTML attribute.

### CommandPaletteStatus

| Prop | Type | Default | Purpose |
|---|---|---|---|
| `busy?` | `boolean` | `false` |  |

Also accepts every native `<div>` attribute; from Base UI: `render`.

### CommandPaletteTrigger

| Prop | Type | Default | Purpose |
|---|---|---|---|
| `label?` | `string` | `"Search"` | The words in the field look-alike. |

Also accepts every native `<button>` attribute; from Base UI: `handle`, `id`, `nativeButton`, `payload`, `render`.

Notes only; gen-docs writes the table.
- `shortcut` on `CommandPalette`: the letter held with Command or Control, "k" by default, or `false` when two palettes share a page. The trigger's field look-alike shows the keys only while there is a shortcut, so a palette with `shortcut={false}` shows no keys that do nothing, and it draws them on the card's colour, so they read as keys on the field's grey in both themes (`registry/cobalt/ui/command-palette.tsx:144-154`).
- `open`, `defaultOpen` and `onOpenChange` on `CommandPalette`; clear the search in `onOpenChange` as it opens.
- `items` on `CommandPaletteContent`: a flat list, or groups of `{ value, items }`; `value` and `onValueChange` are the field's text; `filter={null}` when a server filters.
- `label` on `CommandPaletteContent`: the window's name, "Search" by default.
- `closeLabel` on `CommandPaletteInput`: the Esc button's name.
- `closeOnClick` on `CommandPaletteItem`: true by default.
- `CommandPaletteItemDescription`: a row's second line; put it and the name in one column, `<span className="flex min-w-0 flex-1 flex-col">`.
- `text` and `query` on `CommandPaletteMatch`: the row's words and the field's text; it marks each word of the query wherever it turns up, without regard to case.

The palette takes no row limit. Base UI's `Autocomplete.Root` passes its `limit` through to the list, but it caps the whole list, not each group, so it cannot keep 8 rows per group; the host slices each group instead (`rule/command-palette-rows-per-group`).
- `busy` on `CommandPaletteList` and `CommandPaletteStatus`: pass `useSlowWait(pending)`. On the list it dims the rows; on the status it spins the field's glyph and reads the status's words aloud without showing them.
- `label` on `CommandPaletteTrigger`: the words of the field look-alike; `render` swaps in another control.

## Usage

### When to use
- A research or admin tool where people jump to a known record by name, from any page.
- A keyboard-first tool with commands worth reaching without the pointer.

### When not to use
- Picking a value in a form. Use Combobox instead.
- Filtering the list on the page. Use InputGroup instead, as a search box over the list.
- A few commands for one thing. Use DropdownMenu instead.

### Rules
- `rule/command-palette-one-per-app`: When an app has a palette, mount one `CommandPalette` with the default `shortcut` near its root, and pass `shortcut={false}` to any other on the page instead of a second Command K, because two listeners both toggle on one press. Evidence: app 3/4 palettes in the examples set `shortcut={false}` beside the default one (`docs/system/examples/command-palette/async.tsx:78`, `docs/system/examples/command-palette/in-section.tsx:35`, `docs/system/examples/command-palette/error.tsx:46`); principle input: keyboard, one shortcut has one meaning. Check: review.
  - Don't: two `<CommandPalette>` on one page, both with the default shortcut
  - Do: `<CommandPalette shortcut={false}>` for the second
- `rule/command-palette-clear-on-open`: When the palette opens, start with an empty field and the Recent group, by setting the text to "" in `onOpenChange` as it opens, instead of the last search, because the last search narrows the list to what the person no longer looks for. Evidence: measured 0 characters in the field after a reopen, `.design-system/evidence/command-palette/measure.json`; principle heuristic: recognition rather than recall. Check: review.
  - Don't: `<CommandPalette>` with `value={query}` that is never reset
  - Do: `<CommandPalette onOpenChange={(open) => open && setQuery("")}>`
- `rule/command-palette-async-waits`: When results come from a server, pass `filter={null}`, keep the last results while the next request runs, and show `busy` and the "Searching" status only from `useSlowWait(pending)`, instead of clearing the list, because an answer under 250ms then changes nothing on screen. Evidence: single use docs/system/examples/command-palette/async.tsx:82; person D39. Check: review.
  - Don't: `{pending ? <Spinner /> : <CommandPaletteList>{...}</CommandPaletteList>}`
  - Do: `<CommandPaletteStatus busy={slow}>{slow ? "Searching" : null}</CommandPaletteStatus><CommandPaletteList busy={slow}>`, which spins the field's glyph and keeps the rows where they are
- `rule/command-palette-search-settles`: When results come from a server, send the search once the field holds at least 2 characters and 150ms have passed without a keystroke, and show what the empty field shows until then, instead of a request per keystroke, because one letter matches nearly every record and a name typed at speed is 6 to 10 requests whose answers arrive out of order. Evidence: single use docs/system/examples/command-palette/async.tsx:46; principle heuristic: visibility of system status, a list that changes on every letter cannot be read. Check: review of every `filter={null}` palette.
  - Don't: `useEffect(() => void search(query).then(setResults), [query])`
  - Do: `useEffect(() => { if (query.trim().length < 2) return; const t = setTimeout(() => void search(query).then(setResults), 150); return () => clearTimeout(t); }, [query])`
- `rule/command-palette-error-offers-retry`: When a server search fails, say so in `CommandPaletteStatus` where the results were, with a Retry `Button`, and keep the text in the field, instead of an Empty sentence or a `toast()`, because "nothing matches" after a failure tells the person their record does not exist. Evidence: single use docs/system/examples/command-palette/error.tsx:55; person D39. Check: review of every `filter={null}` palette.
  - Don't: `<CommandPaletteEmpty>{failed ? "No results" : null}</CommandPaletteEmpty>`
  - Do: `<CommandPaletteStatus>{failed ? <>Search is unavailable. <Button size="sm" onClick={retry}>Retry</Button></> : null}</CommandPaletteStatus>`
- `rule/command-palette-mark-the-match`: When a row's name holds the typed words, wrap the name in `CommandPaletteMatch` with the field's text, instead of bold or coloured spans by hand, because the match is then a `mark` underlined as well as tinted, so it reads without colour, and its weight never changes as the query grows. Evidence: single use docs/system/examples/command-palette/default.tsx:81; principle wcag: 1.4.1 Use of color. Check: test `command-palette.test.tsx` renders each match in a `mark`.
  - Don't: `<span>{name.split(query).join("<b>" + query + "</b>")}</span>`
  - Do: `<CommandPaletteMatch text={item.label} query={query} />`
- `rule/command-palette-not-the-only-path`: When a command lives in the palette, give it a visible home too, such as a `Button`, a menu item or a link on its page, instead of the palette alone, because a touch screen has no Command K and a new user does not know the palette exists. Evidence: principle heuristic: recognition rather than recall; principle input: touch, a phone has no Command K. Check: review.
  - Don't: "Export watchlist as CSV" only in the palette
  - Do: an Export `Button` on the watchlist, and the same command in the palette

### Content
- `rule/command-palette-row-names-the-record`: When a row stands for a record, show its name first and where it lives or what it is in `CommandPaletteItemHint`, such as "Boston" or "$1.2B", instead of a type prefix such as "Adviser: Alder Point Capital", because the name is what was typed and the group already says the type. Evidence: app 9/9 rows in default.tsx put the name first (`docs/system/examples/command-palette/default.tsx:81-83`); principle heuristic: match between system and the real world. Check: review.
  - Don't: `<CommandPaletteItem value={a}>Adviser: Alder Point Capital</CommandPaletteItem>`
  - Do: `<CommandPaletteItem value={a}>Alder Point Capital<CommandPaletteItemHint>Boston</CommandPaletteItemHint></CommandPaletteItem>`
- `rule/command-palette-command-is-a-verb`: When a row runs a command, start it with a verb and its object, such as "Export watchlist as CSV", instead of a noun such as "Export", because a command row sits among records and the verb tells them apart. Evidence: app 2/2 commands in default.tsx start with a verb (`docs/system/examples/command-palette/default.tsx:52`); principle heuristic: match between system and the real world. Check: review.
  - Don't: `entry("command", "Watchlist CSV", "File")`
  - Do: `entry("command", "Export watchlist as CSV", "File")`

### Anti-slop
- `rule/command-palette-not-a-dialog-with-a-list`: When an app needs a jump-to search, use `CommandPalette` instead of a `Dialog` holding an `Input` and a mapped list, because the hand-built one has no `aria-activedescendant`, no highlight on open and no announced empty state, and needs its own Command K. Evidence: principle platform: the ARIA combobox pattern; single use registry/cobalt/ui/command-palette.tsx:305. Check: review.
  - Don't: `<Dialog><DialogContent><Input /><ul>{hits.map(...)}</ul></DialogContent></Dialog>`
  - Do: `<CommandPalette><CommandPaletteContent items={groups}><CommandPaletteInput /><CommandPaletteList>{...}</CommandPaletteList></CommandPaletteContent></CommandPalette>`
- `rule/command-palette-no-scale`: When the palette opens, let it fade in place as it does, instead of adding a scale or a slide through `className`, because it opens many times a day and the system never scales a popup. Evidence: person D36; person D14. Check: lint rule/component-override (scripts/check-system.mjs).
  - Don't: `<CommandPaletteContent className="data-starting-style:scale-95">`
  - Do: `<CommandPaletteContent items={groups}>`

### Limits
- `rule/command-palette-rows-per-group`: When a group would hold more than 8 rows, show the best 8 and put the rest behind a row such as "Show all 48 advisers", instead of all of them, because the list shows 6 rows at 1440x900 and 7 at 390x844, so a long first group hides every other group. Evidence: measured 6 rows in view at 1440x900 and 7 at 390x844, `.design-system/evidence/command-palette/measure.json`. Check: probe /stress/command-palette?data=worst.
  - Don't: 50 advisers in one group
  - Do: 8 advisers and `<CommandPaletteItem value={more}>Show all 48 advisers</CommandPaletteItem>`

## Accessibility
Rests on Base UI `Dialog` for the modal window and Base UI `Autocomplete`, inline, for the field and its listbox. Focus stays in the field while the arrows move the highlight.

### Keyboard
| Key | Where focus is | Effect | Focus after | Checked by |
|---|---|---|---|---|
| Command K or Control K | anywhere on the page | opens the window, or closes it when open | the field | by hand |
| Enter or Space | the trigger | opens the window | the field | by hand |
| typing | the field | narrows the rows; the first match is highlighted | the field | by hand |
| ArrowDown or ArrowUp | the field | moves the highlight, across groups | the field, with `aria-activedescendant` | by hand |
| Enter | the field, a row highlighted | runs the row and closes the window | the trigger | by hand |
| Escape | the field | closes the window | the trigger | by hand |
| Tab | the field | moves to the Esc button, the only other stop | the Esc button | by hand |

Measured on the showcase (`.design-system/evidence/command-palette/measure.json`): focus in the field after Command K, the first row highlighted, focus on the trigger after Enter and after Escape, and the field empty on reopen.

### ARIA
| Part | Role | Accessible name from | States and properties | Announced | Checked by |
|---|---|---|---|---|---|
| trigger | button | its words, or `label` | `aria-haspopup="dialog"`, `aria-expanded` | the name and "collapsed" | test |
| shortcut hint | none, `kbd` | the key names, "Command" or "Control" and "K" | none | the keys | test |
| window | dialog, modal | `label` | `aria-modal` | the name and "dialog" as it opens | by hand |
| field | combobox | `aria-label` from its placeholder or the host | `aria-expanded`, `aria-activedescendant`, `aria-controls` | the name, "combo box" | by hand |
| list | listbox | the field | `aria-busy` while `busy` | the number of rows | by hand |
| group | group | its label | none | the label as you enter it | by hand |
| row | option | its text, the name, its second line, then the hint | `aria-selected` on the highlight | the text | by hand |
| matched words | none, `mark` | none | none | the words, in the row's text | test |
| Enter glyph | none, `aria-hidden` | none | none | nothing; the footer names the key | by hand |
| Empty, Status | status, `aria-live="polite"` | none | none | the sentence, once | by hand |
| key hints | none, `aria-hidden` | none | none | nothing; the keys are the platform's | by hand |

## Tokens
| Part | State | Token |
|---|---|---|
| window | open | `--popover`, `--popover-foreground`, `--r-3xl`, `--shadow-floating`, `--t-arrive`, `--gutter` |
| scrim | open | `--scrim` through `Overlay` |
| field row | all | 56px, text-base, the glyph in `--muted-foreground` |
| row | rest | 38px, `--r-lg` inside `--pad-popup`; about 52px with a second line |
| matched words | all | `--primary-ink`, an underline at 40 percent |
| Enter glyph | highlighted | `--muted-foreground` |
| row | highlighted | `--accent`, `--accent-foreground` |
| hint, group label, Empty, footer | all | `--muted-foreground` |
| list | busy | opacity 55 percent, `--t-fade` |
| trigger | all | `--control`, `--r-lg`, `--input` at 50 percent, `--muted-foreground` |

Measured (`.design-system/evidence/command-palette/measure.json`): the window 576px wide and 96px from the top at 1440x900, 358px wide and 16px from the top at 390x844, with 38px rows. The window's corner is `--r-3xl`, 16px by default, and a highlighted row's 10px corner sits 6px in from it.

## Related
- Combobox: picks a value for a form field.
- Dialog: a window for one short task.
- DropdownMenu: a few commands from a button.
- Input: the search field over a list on the page, its glyph inside the box.
- Kbd: the keys in the hints.
- Composer: writes a message or a prompt: a field that grows, files, emoji and a send button that says why it waits.
- Keyboard shortcuts: the app's key bindings and the dialog that lists them.
