Command

A headless command palette with search filtering, keyboard navigation, and grouped options.

Features

  • Built-in filtering
  • Keyboard-first
  • Grouped options
  • Fallback content
  • Controlled or uncontrolled
  • Headless styling

Installation

npm install @ariaui/command

Examples

Command palette with grouped options, typeahead filtering, optional shortcut hints, a clear control via Command.Button, and a "no results" fallback.

Styling uses semantic tokens from @ariaui/tokens; icons are from @heroicons/react/24/outline. The fence is generated from the same JSX as the preview.

Compatible native hosts

Content, Empty, Label, Loading, Option, and Separator accept asChild (default false) for one compatible native DIV host. A custom component must pass through props and forward its HTMLDivElement ref. Native props/events stay narrow; this is not an as/render API. Root, Group, and Input keep their native/generated structures and do not accept asChild.

Filtering can remove an option's DOM host without deleting its searchable metadata. Actual Content/Option IDs remain linked through renames and replacement; keyboard navigation from Input keeps focus there, while native pointer focus may move to the option. Child cancellation skips composed owner selection, while unavailable options block activation before child capture without swallowing ordinary navigation. Empty depends on registered metadata and zero visible results; Label does not automatically name Input, and Loading remains explicitly controlled.

Default

Default command menu using @ariaui/command with grouped options, filtering, and an empty state.

Preview

No preview output yet.

live.tsxReady

Anatomy

tsx
import * as Command from "@ariaui/command";

export default function Example() {
  return (
    <Command.Root>
      <Command.Input />
      <Command.Content>
        <Command.Empty />
        <Command.Group>
          <Command.Label />
          <Command.Option />
        </Command.Group>
        <Command.Separator />
        <Command.Loading />
      </Command.Content>
    </Command.Root>
  );
}

API Reference

Root

State container on a focusable wrapper. Owns selection, search filtering, grouped visibility, and keyboard routing.

PropTypeDefault
value
string—
defaultValue
string""
onValueChange
(value: string) => void—
searchValue
string—
defaultSearchValue
string""
onSearchValueChange
(value: string) => void—
filter
(value: string, search: string, keywords?: string[]) => boolean | numbersubstring match
shouldFilter
booleantrue
label
string—
loop
booleanfalse
disablePointerSelection
booleanfalse
AttributeValues
tabIndex-1 (wrapper receives bubbled keyboard events)

Input

Combobox input wired to Root search state. Typing filters options by default.

PropTypeDefault
onValueChange
(value: string) => void—
value
string—
AttributeValues
rolecombobox
aria-controlsID of Content listbox
aria-labelledbyHidden label from Root
aria-autocompletelist
aria-activedescendantID of active Option
aria-expandedtrue

Content

Listbox region for options and structural helpers.

PropTypeDefault
asChild
booleanfalse
label
string"Suggestions"
AttributeValues
rolelistbox
aria-activedescendantID of the active Option

Empty

Renders only when registered option metadata exists but no options are visible after filtering.

PropTypeDefault
asChild
booleanfalse
AttributeValues
rolepresentation

Loading

Progressbar slot for async data.

PropTypeDefault
asChild
booleanfalse
label
string"Loading..."
progress
number—
AttributeValues
roleprogressbar

Group

Groups options. Stays hidden when every child option is filtered out unless `forceMount`.

PropTypeDefault
heading
React.ReactNode—
forceMount
booleanfalse
value
string—
AttributeValues
rolegroup
aria-labelledbyWhen heading is provided
hiddenWhen no visible children

Label

Standalone label element for custom layouts.

PropTypeDefault
asChild
booleanfalse

Option

Selectable row. Filters against search text unless `forceMount`.

PropTypeDefault
asChild
booleanfalse
value*
string—
disabled
booleanfalse
keywords
string[][]
forceMount
booleanfrom Group
onSelect
(value: string) => void—
AttributeValues
roleoption
aria-selectedMatches active highlight (typeahead / pointer / keyboard)
aria-disabledWhen disabled
data-selectedMirror of active highlight
data-disabledWhen disabled
data-valueOption value string

Separator

Divides groups; hides while searching unless `alwaysRender`.

PropTypeDefault
asChild
booleanfalse
alwaysRender
booleanfalse
AttributeValues
roleseparator

Keyboard

ShortcutAction
↓Move active highlight to the next option; wraps when `loop` is true.
↑Move active highlight to the previous option; wraps when `loop` is true.
Ctrl+N/Ctrl+JMove active highlight down; wraps when `loop` is true (same as ArrowDown).
Ctrl+P/Ctrl+KMove active highlight up; wraps when `loop` is true (same as ArrowUp).
HomeMove to the first enabled visible option.
EndMove to the last enabled visible option.
EnterSelect the active option (updates `value` and runs `onSelect`).

Accessibility

The Command primitives implement the WAI-ARIA Combobox pattern adapted for command palette use:

  • Input carries role="combobox" with aria-controls pointing to the Content listbox and aria-autocomplete="list".

  • Content renders as role="listbox" and tracks the active option via aria-activedescendant.

  • Each Option exposes role="option" with aria-selected when active and aria-disabled when disabled.

  • DOM focus stays on the Input during keyboard navigation; the active option is communicated via aria-activedescendant.

  • Separator uses role="separator" for proper semantics between groups.

Previous
Combobox