Command
A searchable list of actions for command palettes and quick switchers.
Anatomy
<Command.Root>
<Command.Label />
<Command.Control>
<Command.Input />
</Command.Control>
<Command.List>
<Command.ItemGroup>
<Command.ItemGroupLabel />
<Command.Item>
<Command.ItemText />
</Command.Item>
</Command.ItemGroup>
</Command.List>
<Command.Empty />
</Command.Root>
Examples
Basic
Pass a collection to Command.Root and render the filtered items from Command.Context. Typing filters the items,
the arrow keys, Home, and End move the highlight while focus stays in the input, and Enter or a click calls onSelect.
Dialog
Put the command inside a Dialog to build a command palette. Open it with a keyboard shortcut using useHotkey, and
give the dialog content an aria-label.
Groups
Use groupBy on the collection and render collection.group() with ItemGroup and ItemGroupLabel. Groups with no
matching items are not rendered. Disabled items are skipped by the keyboard.
Empty State
Command.Empty renders its children when no item matches the input.
Keywords
Items match on their text and on an optional keywords array, so a command can be found by words that aren't in its
label.
Pages
Give an item a parent value to place it on that item's page. Selecting the parent opens its page instead of calling
onSelect, and Backspace in an empty input goes back. Use pages, setPage, and isPage from the context to render
breadcrumbs and page indicators.
Async
To load items from a server, update the collection as the input value changes, pass a filter that keeps every item,
and set loading while the request is in flight.
Root Provider
Use the useCommand hook with RootProvider to control the command from outside, for example to clear the input.
Guides
Custom filtering
The default filter is a case-insensitive, accent-insensitive match on the item text and its keywords. Pass filter to
match your own way.
<Command.Root collection={collection} filter={(itemText, inputValue) => itemText.startsWith(inputValue)} />
Accessibility
The input is a combobox that controls the listbox and points to the highlighted option with aria-activedescendant,
so focus never leaves the input. Result counts are announced to screen readers. Label the command with Command.Label,
and label the dialog when you render it in one.