# Command

A searchable command palette for actions and destinations.

A searchable command palette for actions and destinations. Arrow keys move the highlight, Enter runs the active row, and focus stays in the search field.

<p className="zenos-base-ui-source">
  Backed by <a href="https://base-ui.com/react/components/combobox">Base UI Combobox</a> and{" "}
  <a href="https://base-ui.com/react/components/dialog">Dialog</a> for filtering, keyboard
  navigation, and the modal shell. Zenos owns the public API, styling, and composition shown on this
  page.
</p>

```tsx
import { GearIcon, HouseIcon, LifebuoyIcon, MagnifyingGlassIcon, PlusIcon, UsersIcon } from "@phosphor-icons/react";
import { Command, InputGroup, Kbd, Stack, Text } from "@zentara-co/zenos-ui";
import { useState } from "react";

const commandActions = [
  { value: "new-project", label: "New project", keywords: ["create"] },
  { value: "invite", label: "Invite teammate" },
];

const commandIcons = {
  "new-project": <PlusIcon />,
  invite: <UsersIcon />,
  dashboard: <HouseIcon />,
  account: <GearIcon />,
  support: <LifebuoyIcon />,
};

function CommandDialogExample() {
  const [open, setOpen] = useState(false);
  const [lastRun, setLastRun] = useState("None");

  return (
    <Stack gap="3" align="start" className="w-full">
      <InputGroup className="w-full max-w-md cursor-pointer" onClick={() => setOpen(true)}>
        <InputGroup.Addon align="inline-start">
          <MagnifyingGlassIcon />
        </InputGroup.Addon>
        <InputGroup.Input
          readOnly
          aria-label="Search components"
          placeholder="Search components..."
          className="cursor-pointer"
          onKeyDown={(event) => {
            if (event.key === "Enter" || event.key === " ") {
              event.preventDefault();
              setOpen(true);
            }
          }}
        />
        <InputGroup.Addon align="inline-end">
          <Kbd keys="mod+k" />
        </InputGroup.Addon>
      </InputGroup>
      <Command.Dialog
        label="Quick actions"
        items={commandActions}
        open={open}
        onOpenChange={setOpen}
        onSelect={setLastRun}
      >
        <Command.Input placeholder="Search actions" />
        <Command.Empty>No results found.</Command.Empty>
        <Command.List>
          {(action: (typeof commandActions)[number]) => (
            <Command.Item
              key={action.value}
              value={action.value}
              icon={commandIcons[action.value as keyof typeof commandIcons]}
            >
              {action.label}
            </Command.Item>
          )}
        </Command.List>
      </Command.Dialog>
      <Text size="s" color="subtle">
        Last run: {lastRun}
      </Text>
    </Stack>
  );
}
```

## Import

```tsx
import { Command } from "@zentara-co/zenos-ui";
```

## Anatomy

`Command` is the inline palette. `Command.Dialog` renders that same palette in a modal. Pass `items` as a flat list or as groups, and render the filtered rows from `Command.List`.

```tsx
<Command label="Quick actions" items={actions}>
  <Command.Input placeholder="Search actions" />
  <Command.List>
    {(action) => (
      <Command.Item key={action.value} value={action.value} onSelect={action.run}>
        {action.label}
      </Command.Item>
    )}
  </Command.List>
  <Command.Empty>No results found.</Command.Empty>
</Command>
```

Each row's searchable identity is its `value`. Add `keywords` on the item for synonyms. A row that does not match is removed, and a group with no remaining rows is removed with it. Disabled rows stay visible and drop out of keyboard navigation.

## Inline

Use `Command` directly to embed the palette in a page. It brings its own surface. Pass `icon` on `Command.Item` for a leading glyph. The shortcut hint on the search row is decorative.

```tsx
import { GearIcon, HouseIcon, LifebuoyIcon, PlusIcon, UsersIcon } from "@phosphor-icons/react";
import { Command, Kbd, Stack, Text } from "@zentara-co/zenos-ui";
import { useState } from "react";

const commandIcons = {
  "new-project": <PlusIcon />,
  invite: <UsersIcon />,
  dashboard: <HouseIcon />,
  account: <GearIcon />,
  support: <LifebuoyIcon />,
};

const commandGroups = [
  {
    label: "Create",
    items: [
      { value: "new-project", label: "New project", keywords: ["create"] },
      { value: "invite", label: "Invite teammate" },
    ],
  },
  {
    label: "Navigate",
    items: [
      { value: "dashboard", label: "Dashboard" },
      { value: "account", label: "Account" },
      { value: "support", label: "Support", disabled: true },
    ],
  },
];

function CommandInlineExample() {
  const [lastRun, setLastRun] = useState("None");

  return (
    <Stack gap="3" className="w-full max-w-md">
      <Command label="Quick actions" items={commandGroups} className="w-full">
        <Command.Input placeholder="Search actions" shortcut={<Kbd keys="mod+k" />} />
        <Command.Empty>Nothing matches that.</Command.Empty>
        <Command.List>
          {(group: (typeof commandGroups)[number]) => (
            <Command.Group key={group.label} heading={group.label} items={group.items}>
              <Command.Collection>
                {(action: (typeof group.items)[number]) => (
                  <Command.Item
                    key={action.value}
                    value={action.value}
                    disabled={"disabled" in action ? action.disabled : undefined}
                    icon={commandIcons[action.value as keyof typeof commandIcons]}
                    onSelect={() => setLastRun(action.label)}
                  >
                    {action.label}
                    {"disabled" in action && action.disabled ? (
                      <Command.Shortcut>Offline</Command.Shortcut>
                    ) : null}
                  </Command.Item>
                )}
              </Command.Collection>
            </Command.Group>
          )}
        </Command.List>
      </Command>
      <Text size="s" color="subtle">
        Highlight with the arrow keys and run with Enter. Last run: {lastRun}
      </Text>
    </Stack>
  );
}
```

## Keyboard

The search field keeps focus. The active row is announced through `aria-activedescendant`. Arrow keys move the highlight, Enter runs the highlighted row, and the query stays as typed. Inside `Command.Dialog`, Escape closes the dialog. The Esc hint in the search row closes it too.

Open the dialog from a key binding in the application that owns the palette. ⌘K and Ctrl+K are the usual pair. The component does not listen for that shortcut itself.

```tsx
useEffect(() => {
  function onKeyDown(event: KeyboardEvent) {
    if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === "k") {
      event.preventDefault();
      setOpen((open) => !open);
    }
  }
  document.addEventListener("keydown", onKeyDown);
  return () => document.removeEventListener("keydown", onKeyDown);
}, []);
```

## Density

`density="comfortable | compact"` inherits the nearest `DensityProvider`. Compact tightens the search row and the action rows. Color and radius stay the same.

```tsx
import { Command, Stack, Text } from "@zentara-co/zenos-ui";

const commandActions = [
  { value: "new-project", label: "New project", keywords: ["create"] },
  { value: "invite", label: "Invite teammate" },
];

function CommandDensityExample() {
  return (
    <Stack direction="row" gap="4" wrap="wrap" align="start" className="w-full justify-center">
      {(["comfortable", "compact"] as const).map((density) => (
        <Stack key={density} gap="2" className="w-full max-w-xs">
          <Text size="s" color="subtle" className="capitalize">
            {density}
          </Text>
          <Command density={density} label={`${density} actions`} items={commandActions}>
            <Command.Input placeholder="Search actions" />
            <Command.List>
              {(action: (typeof commandActions)[number]) => (
                <Command.Item key={action.value} value={action.value}>
                  {action.label}
                </Command.Item>
              )}
            </Command.List>
          </Command>
        </Stack>
      ))}
    </Stack>
  );
}
```

## Command or another component

Use Command for an open-ended, searchable list of actions or destinations. Use [Combobox](/components/combobox/) or [Select](/components/select/) when the person is choosing a value for a field. Use [Dropdown Menu](/components/dropdown-menu/) for a short fixed set of actions.

## Anatomy

```text
Command.Root
Command.Input
Command.List
Command.Empty
Command.Group
Command.GroupLabel
Command.Item
Command.Separator
Command.Shortcut
Command.Dialog
```

## API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| items | Item[] \| { items: Item[]; label?: string }[] | — | Flat rows or groups. A row is a string or { value, label, keywords, disabled }. |
| label | string | — | Accessible name for the search field and the result list. |
| search / defaultSearch / onSearchChange | string / string / (search: string) => void | — | The query, controlled or uncontrolled. |
| filter | (item, query) => boolean \| null | — | Return false to hide a row. Null shows every row. The default match includes label, value, and keywords. |
| onSelect | (value: string) => void | — | Runs after the chosen row's own onSelect. |
| Item.onSelect | (value: string) => void | — | Runs when that row is chosen with the pointer or Enter. |
| Item.icon | ReactNode | — | Leading icon for the row. The label stays in the children. |
| density | comfortable \| compact | comfortable | Controls the search row and item padding. Inherits from DensityProvider when omitted. |
| Dialog.open / defaultOpen / onOpenChange | boolean / boolean / (open: boolean) => void | — | Dialog open state. |
| Dialog.closeOnSelect | boolean | true | Closes the dialog after a row is chosen. |
| Dialog.title / description | string | — | Visually hidden names for the dialog. |
| className | string | — | Merged last on every part. |
| native props | React.HTMLAttributes<HTMLDivElement> | — | Forwards native attributes, events, aria-*, data-*, className, style, and ref. |

Unless narrowed above, each DOM-rendering part also accepts its underlying native or Base UI props, including className, style, aria-*, and data-*.

## Accessibility

`label` names the search field and the result list. Give the dialog its own `title` and `description`; both are visually hidden. Keep empty-state text meaningful, and name each group with `heading` or `Command.GroupLabel` so arrow keys can move through its rows.

Source: https://zenos-ui.pages.dev/components/command/