# Command

A searchable menu of commands, with keyboard shortcuts.

Source: [command.tsx](https://github.com/jakejarvis/jarvis-ui/blob/main/src/components/ui/command.tsx)

```tsx
import {
  ArchiveIcon,
  CalendarDaysIcon,
  FolderIcon,
  PlusIcon,
  SettingsIcon,
  UsersIcon,
  type LucideIcon,
} from "lucide-react";
import * as React from "react";

import { Badge } from "@/components/ui/badge";
import {
  Command,
  CommandCollection,
  CommandEmpty,
  CommandGroup,
  CommandInput,
  CommandItem,
  CommandList,
  CommandSeparator,
} from "@/components/ui/command";
import { Status } from "@/components/ui/status";
import { toast } from "@/components/ui/toast";

type Action = {
  value: string;
  label: string;
  icon: LucideIcon;
  active?: boolean;
  disabled?: boolean;
};

type Group = { value: string; items: Action[] };

const groups: Group[] = [
  {
    value: "Projects",
    items: [
      { value: "website-redesign", label: "Website redesign", icon: FolderIcon, active: true },
      { value: "mobile-app", label: "Mobile app", icon: FolderIcon },
      { value: "brand-guidelines", label: "Brand guidelines", icon: FolderIcon },
    ],
  },
  {
    value: "Actions",
    items: [
      { value: "new-task", label: "New task", icon: PlusIcon },
      { value: "invite-people", label: "Invite people", icon: UsersIcon },
      { value: "open-calendar", label: "Open calendar", icon: CalendarDaysIcon },
      { value: "settings", label: "Settings", icon: SettingsIcon },
      { value: "archive-project", label: "Archive project", icon: ArchiveIcon, disabled: true },
    ],
  },
];

export default function CommandBasic() {
  return (
    <Command items={groups} className="h-80 w-full max-w-md">
      <CommandInput placeholder="Search projects and actions…" />
      <CommandList>
        {(group: Group, index: number) => (
          <React.Fragment key={group.value}>
            {index > 0 && <CommandSeparator />}
            <CommandGroup items={group.items} heading={group.value}>
              <CommandCollection>
                {(item: Action) => (
                  <CommandItem
                    key={item.value}
                    value={item}
                    disabled={item.disabled}
                    onSelect={() => toast.add({ title: item.label })}
                  >
                    <item.icon />
                    {item.label}
                    {item.active && (
                      <Status variant="success" className="ml-auto text-xs">
                        Active
                      </Status>
                    )}
                    {item.disabled && (
                      <Badge variant="muted" className="ml-auto">
                        Admins only
                      </Badge>
                    )}
                  </CommandItem>
                )}
              </CommandCollection>
            </CommandGroup>
          </React.Fragment>
        )}
      </CommandList>
      <CommandEmpty>No results found.</CommandEmpty>
    </Command>
  );
}
```

## Installation

Add the registry, once per project:

```bash
npx shadcn@latest registry add @jarvis=https://ui.jarv.is/r/{name}.json
```

Then add the component:

```bash
npx shadcn@latest add @jarvis/command
```

## Usage

```tsx
import {
  Command,
  CommandEmpty,
  CommandInput,
  CommandItem,
  CommandList,
} from "@/components/ui/command";

type Page = { value: string; label: string; href: string };

const pages: Page[] = [
  { value: "inbox", label: "Inbox", href: "/inbox" },
  { value: "projects", label: "Projects", href: "/projects" },
  { value: "settings", label: "Settings", href: "/settings" },
];

export function PageSearch() {
  return (
    <Command items={pages} className="h-64 max-w-sm">
      <CommandInput placeholder="Go to…" />
      <CommandList>
        {(page: Page) => (
          <CommandItem
            key={page.value}
            value={page}
            onSelect={() => window.location.assign(page.href)}
          >
            {page.label}
          </CommandItem>
        )}
      </CommandList>
      <CommandEmpty>No results found.</CommandEmpty>
    </Command>
  );
}
```

Pass the items to `Command` and render each one from the function inside `CommandList`. Typing
filters them by `label`; items without one need an `itemToStringValue`. `CommandEmpty` shows when
nothing matches. An item's `onSelect` runs on click or Enter.

The list never scrolls sideways. Text too long for its row ends in an ellipsis, whether it's an
item's own text, a plain `span` inside it or a group's heading. Components inside an item, such as
a `Badge`, keep their size, and the row cuts off whatever doesn't fit.

To group items, pass an array of groups, each with its own `items`, and render each as a
`CommandGroup` holding a `CommandCollection`. Put a `CommandSeparator` between groups.

## Composition

- `Command`
  - `CommandInput`
  - `CommandList`
    - `CommandItem`
    - `CommandGroup`
      - `CommandCollection`
    - `CommandSeparator`
  - `CommandEmpty`
  - `CommandFooter`
    - `CommandHint`
- `CommandDialog`
  - `CommandDialogTrigger`
  - `CommandDialogContent`

## Examples

### In a dialog

`CommandDialog` puts the menu in a [Dialog](https://ui.jarv.is/components/dialog.md) for a command palette.
`CommandDialogTrigger` opens it, and `shortcut` on `CommandDialog` takes a chord such as `"Mod+K"`
that opens and closes it from anywhere on the page. `CommandDialogContent` holds the `Command`, with
a `title` and `description` for screen readers. Choosing an item with an `onSelect` closes the
dialog.

`shortcut` on an item takes a chord too, shows it, and runs `onSelect` when it's pressed inside the
menu.

```tsx
import {
  CalendarDaysIcon,
  FolderPlusIcon,
  InboxIcon,
  LayoutDashboardIcon,
  PlusIcon,
  SearchIcon,
  SettingsIcon,
  UploadIcon,
  UsersIcon,
  type LucideIcon,
} from "lucide-react";
import * as React from "react";

import { Button } from "@/components/ui/button";
import {
  Command,
  CommandCollection,
  CommandDialog,
  CommandDialogContent,
  CommandDialogTrigger,
  CommandEmpty,
  CommandFooter,
  CommandGroup,
  CommandHint,
  CommandInput,
  CommandItem,
  CommandList,
  CommandSeparator,
} from "@/components/ui/command";
import { Kbd, KbdGroup } from "@/components/ui/kbd";
import { toast } from "@/components/ui/toast";
import { useShortcutDisplay, type ShortcutChord } from "@/hooks/use-shortcut";

type Action = { value: string; label: string; icon: LucideIcon; shortcut?: ShortcutChord };

type Group = { value: string; items: Action[] };

const groups: Group[] = [
  {
    value: "Actions",
    items: [
      { value: "new-task", label: "New task", icon: PlusIcon, shortcut: "Mod+J" },
      { value: "new-project", label: "New project", icon: FolderPlusIcon },
      { value: "invite-people", label: "Invite people", icon: UsersIcon },
      { value: "upload-file", label: "Upload file", icon: UploadIcon },
    ],
  },
  {
    value: "Go to",
    items: [
      { value: "dashboard", label: "Dashboard", icon: LayoutDashboardIcon },
      { value: "inbox", label: "Inbox", icon: InboxIcon },
      { value: "calendar", label: "Calendar", icon: CalendarDaysIcon },
      { value: "settings", label: "Settings", icon: SettingsIcon, shortcut: "Mod+Shift+S" },
    ],
  },
];

export default function CommandInDialog() {
  const shortcut = useShortcutDisplay("Mod+K");

  return (
    <CommandDialog shortcut="Mod+K">
      <CommandDialogTrigger
        render={<Button variant="secondary" className="w-60 justify-between" />}
      >
        <span className="flex items-center gap-1.5 text-muted-foreground">
          <SearchIcon />
          Search…
        </span>
        {shortcut && (
          <KbdGroup>
            {shortcut.keys.map((key) => (
              <Kbd key={key}>{key}</Kbd>
            ))}
          </KbdGroup>
        )}
      </CommandDialogTrigger>
      <CommandDialogContent>
        <Command items={groups}>
          <CommandInput placeholder="Type a command…" />
          <CommandList>
            {(group: Group, index: number) => (
              <React.Fragment key={group.value}>
                {index > 0 && <CommandSeparator />}
                <CommandGroup items={group.items} heading={group.value}>
                  <CommandCollection>
                    {(action: Action) => (
                      <CommandItem
                        key={action.value}
                        value={action}
                        shortcut={action.shortcut}
                        onSelect={() => toast.add({ title: action.label })}
                      >
                        <action.icon />
                        {action.label}
                      </CommandItem>
                    )}
                  </CommandCollection>
                </CommandGroup>
              </React.Fragment>
            )}
          </CommandList>
          <CommandEmpty>No results found.</CommandEmpty>
          <CommandFooter>
            <CommandHint shortcut={["ArrowUp", "ArrowDown"]}>Navigate</CommandHint>
            <CommandHint shortcut="Enter">Open</CommandHint>
            <CommandHint shortcut="Escape" className="ml-auto">
              Close
            </CommandHint>
          </CommandFooter>
        </Command>
      </CommandDialogContent>
    </CommandDialog>
  );
}
```

The trigger shows its chord with `useShortcutDisplay`, which writes it the way the reader's platform
does, such as `⌘` `K` on a Mac and `Ctrl` `K` elsewhere. The [Kbd](https://ui.jarv.is/components/kbd.md)
page covers it, along with `ShortcutChord`, the type of each `shortcut`, which comes from the
same file.

### With a footer

`CommandFooter` goes last in `Command`, under the list, and stays at the bottom while the list
scrolls or `CommandEmpty` shows. It holds hints about the keys the menu takes, or anything else that
belongs under the results. `CommandHint` is one hint: `shortcut` takes a chord, or an array of them
such as `["ArrowUp", "ArrowDown"]`, and shows each as keys before the label, written the way the
reader's platform writes them. It only shows the keys, since the menu already handles the arrows,
Enter and each item's own `shortcut`. Give a hint `className="ml-auto"` to push it, and any after
it, to the far end, as the dialog above does with Esc.

Like `useShortcutDisplay`, a hint can't show its keys until the page hydrates, so it stays hidden
until then. Hints are for keyboard users: screen readers skip them, since the menu's roles already
tell how to move through it. The examples show the footer at every width, but a menu that's mostly
opened on touch screens can hide it on narrow ones with `className="max-sm:hidden"`.

```tsx
import {
  CalendarDaysIcon,
  FolderIcon,
  InboxIcon,
  LayoutDashboardIcon,
  PlusIcon,
  UsersIcon,
  type LucideIcon,
} from "lucide-react";
import * as React from "react";

import {
  Command,
  CommandCollection,
  CommandEmpty,
  CommandFooter,
  CommandGroup,
  CommandHint,
  CommandInput,
  CommandItem,
  CommandList,
  CommandSeparator,
} from "@/components/ui/command";
import { toast } from "@/components/ui/toast";

type Action = { value: string; label: string; icon: LucideIcon };

type Group = { value: string; items: Action[] };

const groups: Group[] = [
  {
    value: "Go to",
    items: [
      { value: "dashboard", label: "Dashboard", icon: LayoutDashboardIcon },
      { value: "inbox", label: "Inbox", icon: InboxIcon },
      { value: "projects", label: "Projects", icon: FolderIcon },
      { value: "calendar", label: "Calendar", icon: CalendarDaysIcon },
    ],
  },
  {
    value: "Actions",
    items: [
      { value: "new-task", label: "New task", icon: PlusIcon },
      { value: "invite-people", label: "Invite people", icon: UsersIcon },
    ],
  },
];

export default function CommandWithFooter() {
  return (
    <Command items={groups} className="h-72 w-full max-w-md">
      <CommandInput placeholder="Search pages and actions…" />
      <CommandList>
        {(group: Group, index: number) => (
          <React.Fragment key={group.value}>
            {index > 0 && <CommandSeparator />}
            <CommandGroup items={group.items} heading={group.value}>
              <CommandCollection>
                {(item: Action) => (
                  <CommandItem
                    key={item.value}
                    value={item}
                    onSelect={() => toast.add({ title: item.label })}
                  >
                    <item.icon />
                    {item.label}
                  </CommandItem>
                )}
              </CommandCollection>
            </CommandGroup>
          </React.Fragment>
        )}
      </CommandList>
      <CommandEmpty>No results found.</CommandEmpty>
      <CommandFooter>
        <CommandHint shortcut={["ArrowUp", "ArrowDown"]}>Navigate</CommandHint>
        <CommandHint shortcut="Enter">Select</CommandHint>
      </CommandFooter>
    </Command>
  );
}
```

## Props

| Part | Extends |
| --- | --- |
| `Command` | [`Autocomplete.Root`](https://base-ui.com/react/components/autocomplete#root) |
| `CommandDialog` | [`Dialog`](https://ui.jarv.is/components/dialog.md) |
| `CommandDialogTrigger` | [`DialogTrigger`](https://ui.jarv.is/components/dialog.md) |
| `CommandDialogContent` | [`DialogContent`](https://ui.jarv.is/components/dialog.md) |
| `CommandInput` | [`Autocomplete.Input`](https://base-ui.com/react/components/autocomplete#input) |
| `CommandList` | [`Autocomplete.List`](https://base-ui.com/react/components/autocomplete#list) |
| `CommandEmpty` | [`Autocomplete.Empty`](https://base-ui.com/react/components/autocomplete#empty) |
| `CommandGroup` | [`Autocomplete.Group`](https://base-ui.com/react/components/autocomplete#group) |
| `CommandCollection` | [`Autocomplete.Collection`](https://base-ui.com/react/components/autocomplete#collection) |
| `CommandSeparator` | [`Autocomplete.Separator`](https://base-ui.com/react/components/autocomplete#separator) |
| `CommandItem` | [`Autocomplete.Item`](https://base-ui.com/react/components/autocomplete#item) |
| `CommandShortcut` | `<span>` |
| `CommandFooter` | `<div>` |
| `CommandHint` | `<span>` |

The tables leave out `className`, `style` and `render`. Parts built on Base UI take them as its [styling](https://base-ui.com/react/handbook/styling) and [composition](https://base-ui.com/react/handbook/composition) guides describe.

### Command

| Prop                    | Type                                                                                                           | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| ----------------------- | -------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `children?`             | `React.ReactNode`                                                                                              |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `name?`                 | `string`                                                                                                       | Identifies the field when a form is submitted.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `id?`                   | `string`                                                                                                       | The id of the component.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| `required?`             | `boolean`                                                                                                      | Whether the user must choose a value before submitting a form. Default: `false`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `readOnly?`             | `boolean`                                                                                                      | Whether the user should be unable to choose a different option from the popup. Default: `false`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `disabled?`             | `boolean`                                                                                                      | Whether the component should ignore user interaction. Default: `false`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `defaultOpen?`          | `boolean`                                                                                                      | Whether the popup is initially open. To render a controlled popup, use the `open` prop instead. Default: `false`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `onOpenChangeComplete?` | `((open: boolean) => void)`                                                                                    | Event handler called after any animations complete when the popup is opened or closed.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `loopFocus?`            | `boolean`                                                                                                      | Whether to loop keyboard focus back to the input when the end of the list is reached while using the arrow keys. The first item can then be reached by pressing <kbd>ArrowDown</kbd> again from the input, or the last item can be reached by pressing <kbd>ArrowUp</kbd> from the input. The input is always included in the focus loop per [ARIA Authoring Practices](https://www.w3.org/WAI/ARIA/apg/patterns/combobox/). When disabled, focus does not move when on the last element and the user presses <kbd>ArrowDown</kbd>, or when on the first element and the user presses <kbd>ArrowUp</kbd>. Default: `true`                                       |
| `inputRef?`             | `React.Ref<HTMLInputElement>`                                                                                  | A ref to the hidden input element.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| `grid?`                 | `boolean`                                                                                                      | Whether list items are presented in a grid layout. When enabled, arrow keys navigate across rows and columns inferred from DOM rows. Default: `false`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `virtualized?`          | `boolean`                                                                                                      | Whether the items are being externally virtualized. Default: `false`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| `modal?`                | `boolean`                                                                                                      | Determines if the popup enters a modal state when open. - `true`: user interaction is limited to the popup: document page scroll is locked and pointer interactions on outside elements are disabled. - `false`: user interaction with the rest of the document is allowed. On touch devices, a `true` modal blocks outside taps but leaves the page scrollable unless the popup spans nearly the full viewport width, matching native iOS behavior. Default: `false`                                                                                                                                                                                           |
| `limit?`                | `number`                                                                                                       | The maximum number of items to display in the list. Default: `-1`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| `locale?`               | `Intl.LocalesArgument`                                                                                         | The locale to use for string comparison. Defaults to the user's runtime locale.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `form?`                 | `string`                                                                                                       | Identifies the form that owns the internal input. Useful when the autocomplete is rendered outside the form.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| `filteredItems?`        | `readonly unknown[] \| readonly Group<unknown>[]`                                                              | Filtered items to display in the list. When provided, the list uses these items instead of filtering the `items` prop internally. When `items` is also provided, this array must preserve its flat or grouped structure. Nullish entries are not supported, as in `items`. Use when you want to control filtering logic externally with the `useFilter()` hook.                                                                                                                                                                                                                                                                                                 |
| `filter?`               | `((item: unknown, query: string, itemToString?: ((item: unknown) => string) \| undefined) => boolean) \| null` | Filter function used to match items against the input query.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| `mode?`                 | `"both" \| "inline" \| "list" \| "none"`                                                                       | Controls how the autocomplete behaves with respect to list filtering and inline autocompletion. - `list` (default): items are dynamically filtered based on the input value. The input value does not change based on the active item. - `both`: items are dynamically filtered based on the input value, which will temporarily change based on the active item (inline autocompletion). - `inline`: items are static (not filtered), and the input value will temporarily change based on the active item (inline autocompletion). - `none`: items are static (not filtered), and the input value will not change based on the active item. Default: `'list'` |
| `autoHighlight?`        | `"always" \| boolean`                                                                                          | Whether the first matching item is highlighted automatically. - `true`: highlight after the user types and keep the highlight while the query changes. - `'always'`: always highlight the first item. Default: `"always"`                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `keepHighlight?`        | `boolean`                                                                                                      | Whether the highlighted item should be preserved when the pointer leaves the list. Default: `true`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| `highlightItemOnHover?` | `boolean`                                                                                                      | Whether moving the pointer over items should highlight them. Disabling this prop allows CSS `:hover` to be differentiated from the `:focus` (`data-highlighted`) state. Default: `true`                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| `defaultValue?`         | `string \| number \| readonly string[]`                                                                        | The uncontrolled input value of the autocomplete when it's initially rendered. To render a controlled autocomplete, use the `value` prop instead.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| `value?`                | `string \| number \| readonly string[]`                                                                        | The input value of the autocomplete. Use when controlled.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `onValueChange?`        | `((value: string, eventDetails: AutocompleteRootChangeEventDetails) => void)`                                  | Event handler called when the input value of the autocomplete changes.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `submitOnItemClick?`    | `boolean`                                                                                                      | Whether clicking an item should submit the autocomplete's owning form. By default, clicking an item via a pointer or <kbd>Enter</kbd> key does not submit the owning form. Useful when the autocomplete is used as a single-field form search input. Default: `false`                                                                                                                                                                                                                                                                                                                                                                                           |
| `itemToStringValue?`    | `((itemValue: unknown) => string)`                                                                             | When the item values are objects (`<Autocomplete.Item value={object}>`), this function converts the object value to a string representation for both display in the input and form submission. If the shape of the object is `{ value, label }`, the label will be used automatically without needing to specify this prop.                                                                                                                                                                                                                                                                                                                                     |
| `actionsRef?`           | `React.RefObject<AutocompleteRootActions \| null>`                                                             | A ref to imperative actions. - `unmount`: Ends the closing phase of the autocomplete after an externally controlled closing animation finishes. Call `preventUnmountOnClose()` in `onOpenChange` first, otherwise the autocomplete completes closing on its own. Whether it leaves the DOM is decided by `keepMounted` on the portal. - `close`: Closes the autocomplete imperatively when called.                                                                                                                                                                                                                                                              |
| `onOpenChange?`         | `((open: boolean, eventDetails: AutocompleteRootOpenChangeEventDetails) => void)`                              | Event handler called when the popup is opened or closed.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| `onItemHighlighted?`    | `((highlightedValue: unknown, eventDetails: AutocompleteRootHighlightEventDetails) => void)`                   | Callback fired when an item is highlighted or unhighlighted. Receives the highlighted item value (or `undefined` if no item is highlighted) and event details with a `reason` property describing why the highlight changed. The `reason` can be: - `'keyboard'`: the highlight changed due to keyboard navigation. - `'pointer'`: the highlight changed due to pointer hovering. The event may be a `MouseEvent` rather than a `PointerEvent`. - `'none'`: the highlight changed for another reason, such as typing, `autoHighlight`, the item list changing, or the popup opening or closing.                                                                 |
| `openOnInputClick?`     | `boolean`                                                                                                      | Whether the popup opens when clicking the input. Default: `false`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| `items?`                | `readonly unknown[]`                                                                                           |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |

### CommandDialog

| Prop                       | Type                                                                     | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| -------------------------- | ------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `open?`                    | `boolean`                                                                | Whether the dialog is currently open.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `defaultOpen?`             | `boolean`                                                                | Whether the dialog is initially open. To render a controlled dialog, use the `open` prop instead. Default: `false`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `modal?`                   | `"trap-focus" \| boolean`                                                | Determines if the dialog enters a modal state when open. - `true`: user interaction is limited to just the dialog: focus is trapped, document page scroll is locked, and pointer interactions on outside elements are disabled. - `false`: user interaction with the rest of the document is allowed. - `'trap-focus'`: focus is trapped inside the dialog, but document page scroll is not locked and pointer interactions outside of it remain enabled. When `modal` is `true` or `'trap-focus'`, render `<Dialog.Close>` inside `<Dialog.Popup>` so touch screen readers can escape the popup. Default: `true` |
| `onOpenChange?`            | `((open: boolean, eventDetails: DialogRoot.ChangeEventDetails) => void)` | Event handler called when the dialog is opened or closed.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| `onOpenChangeComplete?`    | `((open: boolean) => void)`                                              | Event handler called after any animations complete when the dialog is opened or closed.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `disablePointerDismissal?` | `boolean`                                                                | Whether to prevent the dialog from closing on outside presses. For non-modal dialogs, this also prevents the dialog from closing when focus moves outside of it. Default: `false`                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `actionsRef?`              | `React.RefObject<DialogRootActions \| null>`                             | A ref to imperative actions. - `unmount`: Ends the closing phase of the dialog after an externally controlled closing animation finishes. Call `preventUnmountOnClose()` in `onOpenChange` first, otherwise the dialog completes closing on its own. Whether it leaves the DOM is decided by `keepMounted` on the portal. - `close`: Closes the dialog imperatively when called.                                                                                                                                                                                                                                  |
| `handle?`                  | `DialogHandle<unknown>`                                                  | A handle to associate the dialog with a trigger. If specified, allows external triggers to control the dialog's open state. Can be created with the Dialog.createHandle() method.                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `children?`                | `PayloadChildRenderFunction<unknown> \| React.ReactNode`                 | The content of the dialog. This can be a regular React node or a render function that receives the `payload` of the active trigger.                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| `triggerId?`               | `string \| null`                                                         | ID of the trigger that the dialog is associated with. This is useful in conjunction with the `open` prop to create a controlled dialog. There's no need to specify this prop when the dialog is uncontrolled (that is, when the `open` prop is not set).                                                                                                                                                                                                                                                                                                                                                          |
| `defaultTriggerId?`        | `string \| null`                                                         | ID of the trigger that the dialog is associated with. This is useful in conjunction with the `defaultOpen` prop to create an initially open dialog.                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| `shortcut?`                | `ShortcutChord`                                                          | A TanStack Hotkeys chord, such as "Mod+K", that opens and closes the dialog from anywhere on the page.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |

### CommandDialogTrigger

| Prop            | Type                    | Description                                                                                                                                                                                        |
| --------------- | ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `handle?`       | `DialogHandle<unknown>` | A handle to associate the trigger with a dialog. Can be created with the Dialog.createHandle() method.                                                                                             |
| `payload?`      | `unknown`               | A payload to pass to the dialog when it is opened.                                                                                                                                                 |
| `id?`           | `string`                | ID of the trigger. In addition to being forwarded to the rendered element, it is also used to specify the active trigger for the dialog in controlled mode (with the DialogRoot `triggerId` prop). |
| `nativeButton?` | `boolean`               | Whether the component renders a native `<button>` element when replacing it via the `render` prop. Set to `false` if the rendered element is not a button (for example, `<div>`). Default: `true`  |

### CommandDialogContent

| Prop               | Type                                                                                                                          | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| ------------------ | ----------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `initialFocus?`    | `boolean \| React.RefObject<HTMLElement \| null> \| ((openType: InteractionType) => boolean \| HTMLElement \| null \| void)`  | Determines the element to focus when the dialog is opened. By default, focus moves to the first tabbable element inside the popup, except when the dialog is opened by touch — then the popup itself is focused to avoid opening the virtual keyboard. - `false`: Do not move focus. - `true`: Move focus based on the default behavior (first tabbable element or popup). - `RefObject`: Move focus to the ref element. - `function`: Called with the interaction type (`mouse`, `touch`, `pen`, or `keyboard`). Return an element to focus, `true` to use the default behavior, `null` to fall back to the default behavior, or `false`/`undefined` to do nothing. |
| `finalFocus?`      | `boolean \| React.RefObject<HTMLElement \| null> \| ((closeType: InteractionType) => boolean \| HTMLElement \| null \| void)` | Determines the element to focus when the dialog is closed. - `false`: Do not move focus. - `true`: Move focus based on the default behavior (trigger or previously focused element). - `RefObject`: Move focus to the ref element. - `function`: Called with the interaction type (`mouse`, `touch`, `pen`, or `keyboard`). Return an element to focus, `true` to use the default behavior, `null` to fall back to the default behavior, or `false`/`undefined` to do nothing.                                                                                                                                                                                       |
| `title?`           | `string`                                                                                                                      | Names the dialog for screen readers. Default: `"Command Palette"`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| `showCloseButton?` | `boolean`                                                                                                                     | Default: `false`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `description?`     | `string`                                                                                                                      | Describes the dialog for screen readers. Default: `"Search for a command to run..."`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |

### CommandInput

| Prop        | Type      | Description                                                            |
| ----------- | --------- | ---------------------------------------------------------------------- |
| `disabled?` | `boolean` | Whether the component should ignore user interaction. Default: `false` |

### CommandList

| Prop        | Type                                                                 | Description |
| ----------- | -------------------------------------------------------------------- | ----------- |
| `children?` | `((item: any, index: number) => React.ReactNode) \| React.ReactNode` |             |

### CommandGroup

| Prop       | Type              | Description                                                                                                |
| ---------- | ----------------- | ---------------------------------------------------------------------------------------------------------- |
| `items?`   | `readonly any[]`  | Items to be rendered within this group. When provided, child `Collection` components will use these items. |
| `heading?` | `React.ReactNode` |                                                                                                            |

### CommandCollection

| Prop       | Type                                            | Description |
| ---------- | ----------------------------------------------- | ----------- |
| `children` | `(item: any, index: number) => React.ReactNode` |             |

### CommandSeparator

| Prop           | Type                         | Description                                               |
| -------------- | ---------------------------- | --------------------------------------------------------- |
| `orientation?` | `"horizontal" \| "vertical"` | The orientation of the separator. Default: `'horizontal'` |

### CommandItem

| Prop            | Type                                                                           | Description                                                                                                                                                                                                                         |
| --------------- | ------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `nativeButton?` | `boolean`                                                                      | Whether the component renders a native `<button>` element when replacing it via the `render` prop. Set to `true` if the rendered element is a native button. Default: `false`                                                       |
| `children?`     | `React.ReactNode`                                                              |                                                                                                                                                                                                                                     |
| `onClick?`      | `((event: BaseUIEvent<React.MouseEvent<HTMLDivElement, MouseEvent>>) => void)` | An optional click handler for the item when selected. It fires when clicking the item with the pointer, as well as when pressing `Enter` with the keyboard if the item is highlighted when the `Input` or `List` element has focus. |
| `index?`        | `number`                                                                       | The index of the item in the list. Improves performance when specified by avoiding the need to calculate the index automatically from the DOM.                                                                                      |
| `value?`        | `any`                                                                          | A unique value that identifies this item. Default: `null`                                                                                                                                                                           |
| `disabled?`     | `boolean`                                                                      | Whether the component should ignore user interaction. Default: `false`                                                                                                                                                              |
| `onSelect?`     | `(() => void)`                                                                 | Runs on click or Enter, instead of copying the item into the input. Inside a `CommandDialog`, the dialog closes after.                                                                                                              |
| `shortcut?`     | `ShortcutChord`                                                                | A TanStack Hotkeys chord, such as "Mod+J", that runs `onSelect` while focus is inside the Command. It's shown at the end of the row.                                                                                                |

### CommandHint

| Prop        | Type                                        | Description                                                                                                            |
| ----------- | ------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
| `shortcut?` | `readonly ShortcutChord[] \| ShortcutChord` | A TanStack Hotkeys chord, or several, shown as keys before the hint's label. It only shows them, without binding them. |
