CommandPalette
Search and run grouped commands on an inline surface that composes inside a page or dialog.
Anatomy#
Group labels and items flatten into sibling rows when virtualized. With descriptionPosition: 'trailing', the description renders inside itemLabel.
Usage#
Use CommandPalette for searchable commands or navigation targets on an inline surface. The application decides when to open it and registers any global shortcut.
Wrap it in a Dialog or BaseDialog when the palette should occupy a focused overlay; the wrapper also owns Escape dismissal. Use NavigationMenu for persistent site destinations.
Groups and filtering#
Pass items and groups from application state. The palette filters the supplied collection and calls
the item’s onSelect, then the palette’s onSelect. Fetching commands, routing, and global
shortcuts stay with the application.
The default filterMethod is 'contains', which matches the item’s label, value, description, and
keywords ignoring case and accents. Pass 'startsWith', 'endsWith', or a predicate for custom
matching, or false to skip filtering when you already filter the collection. Set alwaysShow on
an item to keep it visible for any query.
By default, selecting an enabled item also calls onCloseRequest. The palette never hides itself:
use onCloseRequest to close the surrounding Dialog or BaseDialog. Set closable to show a close
button that calls onCloseRequest.
The search input takes focus on mount unless the palette sits inside an element with
role="dialog"; set autoFocus={false} to disable it. Control the query with searchValue and
onSearchValueChange, or start from defaultSearchValue.
Custom items and states#
An item’s icon renders before the label and kbds renders keycaps after it in the default item
content; leadingRender and trailingRender replace them with custom content. Use itemRender
when a row needs extra fields such as owner or status; it replaces the default row content, so the
item’s icon, kbds, leadingRender, and trailingRender no longer apply.
Provide emptyRender when an empty query or a miss needs explanation, and footerRender for a
footer such as keyboard hints. Set loading while results are still arriving: it swaps the leading
icon for loadingIcon, and items stay selectable.
Sub-navigation is a short, deliberate branch of commands. Swap the items prop from application
state rather than treating the palette as an application shell. Set closeOnSelect={false} while
the branch stays open.
Keyboard interaction#
| Key | Description |
|---|---|
| ↓ | Highlights the next enabled command. |
| ↑ | Highlights the previous enabled command. |
| ↵ | Selects the highlighted command. |
Focus stays in the search input while the highlight moves. Navigation wraps from the last command to the first. Escape and other dismissal keys belong to the enclosing Dialog or BaseDialog, not the palette.
Examples#
Basic#
Filter grouped commands and handle selection in onSelect.
Custom item#
Render each command row with extra fields. Keep matching against the item model.
Custom empty state#
Replace the default empty copy shown when no command is visible, whether the collection is empty or the query matches nothing.
Loading#
Keep the palette visible while loading is true.
Virtualization#
Pass a virtualizer from createListVirtualizer to render only the rows near the viewport. Its
entries are CommandPaletteT.VirtualEntry rows: group labels and commands flattened into one list.
The listbox keeps its default bounded height, so the virtual range stays stable while scrolling.
Sub-navigation#
Swap items to build nested command pages without closing the palette until a leaf command runs.
API Reference#
Attributes#
data-disableddata-highlighteddata-loading