CommandPalette
Searchable command list with groups, keyboard navigation, and customizable rendering.
Import#
Slot Structure#
CommandPalette renders a searchable grouped list with keyboard navigation, active-descendant semantics, and optional footer content. Compose it with Dialog when it should appear in an overlay; the caller owns the trigger, open state, positioning, and closing behavior.
Input area#
Results#
Examples#
Basic#
Compose Dialog around CommandPalette and put the trigger in Dialog’s children. Handle the selected item with CommandPalette’s onSelect callback; enabled selections request closing by default through onClose.
Real-World Example#
Drive the palette from the same shortcut map you use across the app, and render those bindings with item.trailingRender plus Kbd so the UI and keyboard behavior stay aligned.
Custom Item Render#
Use itemRender when the row layout needs richer metadata than the default label, description, leadingRender, and trailingRender item render hooks.
Description Position#
Set descriptionPosition="trailing" to keep descriptions inline near the label while reserving item.trailingRender for badges, shortcuts, or other metadata.
Custom Empty State#
Override the default ‘No results.’ message.
Loading#
Search icon becomes a spinner while loading.
With Close Button#
A close button in the input trailing slot.
Sub-Navigation#
Compose multi-step flows outside the component by swapping the groups prop in a wrapper and set closeOnSelect={false} while the palette remains open between steps.
Sizes and Virtual Rendering#
Use size="xs" | "sm" | "md" | "lg" | "xl" to size command rows. For large collections, pass virtualRender and scrollToItem; CommandPalette exposes type-safe flattened entries and its mounted scroll element, while scrollToItem receives the source command plus its flattened entry index.
API Reference#
Attributes#
root0 attributesProps#
| Prop | Type | Default | Description |
|---|---|---|---|
| autofocus | boolean | undefined | true | Whether to focus the search input automatically on mount. |
| class | ClassValue | — | Class applied to the component root or trigger element. |
| classes | CommandPaletteT.Classes | undefined | — | — |
| closeIcon | IconT.Name | icon-close | Icon name for the palette close button. |
| closeOnSelect | boolean | undefined | true | Whether to request closing the palette after an enabled item is selected. |
| descriptionPosition | CommandPaletteT.DescriptionPosition | undefined | bottom | Where descriptions render by default. |
| disableFilter | boolean | undefined | false | Disable built-in search filtering and render all provided items. |
| emptyRender | ComponentOrElement<CommandPaletteT.EmptyRenderProps<TItem>> | undefined | — | Custom empty state renderer. |
| filterItems | ((args: { groups: CommandPaletteT.Group<TItem>[]; searchTerm: string; }) => CommandPaletteT.Group<TItem>[]) | undefined | — | Custom filter function that fully controls which groups and items are visible. |
| footerRender | ComponentOrElement<CommandPaletteT.FooterRenderProps<TItem>> | undefined | — | Custom footer renderer. |
| getItemSearchText | ((item: TItem, group: CommandPaletteT.Group<TItem>) => string) | undefined | — | Custom search text builder for built-in filtering. |
| groups | CommandPaletteT.Group<TItem>[] | undefined | [] | Command groups to display initially. |
| inputProps | JSX.HTMLAttributes<HTMLInputElement> | undefined | — | Additional props of input |
| itemProps | ((context: CommandPaletteT.ItemRenderProps<TItem>) => ElementProps<HTMLDivElement> | undefined) | undefined | — | Additional attributes for a command row. |
| itemRender | ComponentOrElement<CommandPaletteT.ItemRenderProps<TItem>> | undefined | — | Custom command row content renderer. |
| leadingIcon | IconT.Name | icon-search | Icon name of input's leading icon. |
| listboxProps | ElementProps<HTMLDivElement> | undefined | — | Additional attributes for the command listbox. |
| loading | boolean | undefined | false | Whether the palette is in a loading state. |
| loadingIcon | IconT.Name | icon-loading | Icon name of input's leading icon for the loading state. |
| onClose | (() => void) | undefined | — | Callback triggered when the close button is clicked or selection requests closing. |
| onSearchTermChange | ((term: string) => void) | undefined | — | Callback triggered when the search term changes. |
| onSelect | ((item: TItem) => void) | undefined | — | Callback triggered when an enabled item is selected. |
| placeholder | string | undefined | Search... | Placeholder text for the search input. |
| ref | JSX.HTMLElementTags["div"] extends { ref?: infer Ref; } ? Ref : never | undefined | — | — |
| scrollToItem | ((item: TItem, entryIndex: number) => void) | undefined | — | Scrolls a highlighted command into view using its flattened entry index. |
| searchMaxLength | number | undefined | — | Maximum allowed length for the search text. |
| searchTerm | string | undefined | — | Controlled search term. |
| showClose | boolean | undefined | false | Whether to show a close button in the header. |
| size | "xs" | "sm" | "md" | "lg" | "xl" | undefined | — | — |
| style | JSX.CSSProperties | undefined | — | — |
| styles | CommandPaletteT.Styles | undefined | — | — |
| virtualRender | Component<CommandPaletteT.VirtualRenderProps<TItem>> | undefined | — | Renders flattened group labels and commands through a virtualization layer. |
Items#
| Prop | Type | Default | Description |
|---|---|---|---|
| alwaysShow | boolean | undefined | — | Whether this item should be excluded from built-in search filtering. |
| description | string | undefined | — | Secondary description text shown for the item. |
| descriptionPosition | CommandPaletteT.DescriptionPosition | undefined | — | Where the item description is rendered. Overrides the root setting. |
| disabled | boolean | undefined | — | Whether the item is disabled and cannot be selected. |
| keywords | string[] | undefined | — | Additional keywords included in built-in search matching. |
| label | string | undefined | — | Primary label for the item. |
| leadingRender | ComponentOrElement<CommandPaletteT.ItemRenderProps> | undefined | — | Custom visual rendered at the start of the item. |
| onSelect | (() => void) | undefined | — | Callback triggered when the item is selected. |
| trailingRender | ComponentOrElement<CommandPaletteT.ItemRenderProps> | undefined | — | Custom visual rendered at the end of the item. |
| value* | string | — | Unique value for the item. |