Command
Command is a command palette that lets people search for any action or page in your app and run it from the keyboard.
<Command items={sections} open={open} onOpenChange={setOpen}> <CommandTrigger render={<Button>Open</Button>} /> <CommandContent aria-label="Command palette"> <CommandInput aria-label="Search" placeholder="Search…" /> <CommandList>{(section) => …}</CommandList> <CommandEmpty>…</CommandEmpty> </CommandContent></Command>Command is a search field over the actions and pages in your app. Someone types a few letters, the list narrows to the matching rows, and Enter runs the highlighted one. Use it for a command palette that opens from a keyboard shortcut. To choose a value in a form, use a Combobox, and for a short list of actions on one object, use a Menu.
The palette is a Dialog, so it dims the page, keeps focus inside, stops the page behind it from scrolling and closes on Escape. It covers the whole app while it is open. For a floating panel that leaves the page usable, use a Popover.
The search field and the results are two separate panels near the top of the window, at every width including a phone. The field stays in place while the results panel below it grows and shrinks as you type. Rows keep the order you wrote them in, so people can learn where each command is.
One size sets the whole palette: both panels, the search field, the rows and the group labels. The rows are one size step larger than the controls in your app, and the text in the search field is larger again, so the palette reads as the main thing on the screen rather than as part of a form.
Pass every command to items, and keep the array stable by defining it at module scope or in a useMemo. CommandList and CommandCollection take a function, which they call for each item that matches. To rank or limit the results yourself, set filter to null on CommandContent, read the text with onQueryChange, and pass your own narrowed array to items.
Your app decides which keys open the palette, so Command accepts open and onOpenChange, and it shows no button when you leave out CommandTrigger. Running a row closes the palette, and onOpenChange reports the reason item-press. Call cancel() for that reason to keep the palette open.
The search field keeps focus the whole time the palette is open. A row is highlighted from the start, the arrow keys move the highlight and Enter runs it, while Tab leaves the list alone. A row rendered as a link is a real anchor, so screen readers announce it as a link and a middle-click opens it in a new tab. CommandContent and CommandInput both need an aria-label, because the palette has no visible title and a placeholder isn't a name.
Topics
Every symbol this component exports, grouped by the job it does. Each one carries the props it declares; each one has an anchor of its own.
Opening the palette
Command
Command is a command palette that lets people search for any action or page in your app and run it from the keyboard.
| Prop | Type | What it does |
|---|---|---|
children | React.ReactNode | A CommandTrigger, if there is one, and a CommandContent. |
defaultOpen? | DialogProps["defaultOpen"] | Whether the palette is open at the start, for an uncontrolled palette. |
items | readonly unknown[] | All the items that the palette can show, before filtering. |
onOpenChange? | (open: boolean, details: CommandOpenChangeDetails) => void | Called each time the palette opens or closes. |
open? | DialogProps["open"] | Whether the palette is open, for a controlled palette. |
size? | "1" | "2" | "3" | "4" | The size step of the palette, from "1" to "4". |
CommandTrigger
The control that opens the palette. Leave it out when a keyboard shortcut is the only way to open it
| Prop | Type | What it does |
|---|---|---|
children? | React.ReactNode | The button's label. |
className? | string | Your classes, appended to the ones this component resolves rather than replacing them. |
nativeButton? | boolean | Tells the part if the rendered element is a real <button>. |
render? | RenderElement | Usually a Kookie Button: <DialogTrigger render={<Button/>}>Delete…</DialogTrigger>. |
style? | React.CSSProperties | Inline styles, merged last, so your value wins over anything the component resolved. |
It also takes every prop of a <button>.
Presenting the panel
CommandContent
Holds the search field and the results. It needs an aria-label, which names the palette for screen readers, and it accepts filter and onQueryChange
| Prop | Type | What it does |
|---|---|---|
aria-label | string | The accessible name of the palette. |
children | React.ReactNode | A CommandInput, a CommandList, and a CommandEmpty for when nothing matches. |
className? | string | Your classes, appended to the ones this component resolves rather than replacing them. |
filter? | React.ComponentPropsWithoutRef<typeof Autocomplete.Root>["filter"] | A custom function that decides which items match the query. |
onQueryChange? | (query: string) => void | Called with the query each time it changes, and with an empty query when the palette closes. |
style? | React.CSSProperties | Inline styles, merged last, so your value wins over anything the component resolved. |
Filtering
CommandInput
The search field, in its own panel above the results. It needs an aria-label, and it shows no focus ring, because it keeps focus the whole time the palette is open
| Prop | Type | What it does |
|---|---|---|
aria-label | string | The accessible name of the search field. |
className? | string | Your classes, appended to the ones this component resolves rather than replacing them. |
leading? | React.ReactNode | Content before the field, such as a search icon. |
CommandEmpty
What the palette shows when nothing matches. Put it next to CommandList, and it appears inside the results panel, so the palette keeps the same shape
| Prop | Type | What it does |
|---|---|---|
children | React.ReactNode | The content to show when no item matches. |
className? | string | Your classes, appended to the ones this component resolves rather than replacing them. |
Listing the commands
CommandList
The scrolling panel of results. It takes a function, which it calls for each item that matches the search
| Prop | Type | What it does |
|---|---|---|
children | (item: T) => React.ReactNode | Called for each item that survives the filter. |
className? | string | Your classes, appended to the ones this component resolves rather than replacing them. |
CommandItem
One command row, with optional leading and trailing content. Set tone="destructive" for a command that deletes something
| Prop | Type | What it does |
|---|---|---|
className? | string | Your classes, appended to the ones this component resolves rather than replacing them. |
leading? | React.ReactNode | Content before the label, such as an icon or an avatar. |
render? | RenderElement | The element to render the row as, such as an <a href> or your framework's link component. |
tone? | "destructive" | The colour of the row. |
trailing? | React.ReactNode | Content at the far end of the row, such as a keyboard shortcut, a category or a count. |
Grouping into sections
CommandGroup
A section of the results with its own items. It hides itself when none of its items match
| Prop | Type | What it does |
|---|---|---|
children | React.ReactNode | A CommandGroupLabel and a CommandCollection for the rows. |
className? | string | Your classes, appended to the ones this component resolves rather than replacing them. |
items | readonly unknown[] | The items in this group. |
| Prop | Type | What it does |
|---|---|---|
children | React.ReactNode | The name of the group. |
className? | string | Your classes, appended to the ones this component resolves rather than replacing them. |
- A footer — A palette footer usually holds a legend of keyboard shortcuts. Each row can already show its own shortcut in
trailing, which is where people look for it. modal— An open palette always covers the page, because it is the one thing someone is doing at that moment. For a panel that leaves the page usable, use aPopover.- Re-sorting results as you type — Rows keep the order you wrote them in. If the order changed on every keystroke, people couldn't learn where a command is. To rank results, filter them yourself and pass the sorted array to
items. - A Separator inside the panel — The results list is a listbox, which may only contain options and groups, so a separator fails accessibility checks. Use
CommandGroupto divide the rows instead. - An edge-to-edge results panel — The results panel keeps padding around its rows, like a menu panel, so a highlighted row ends inside the panel's rounded corner instead of running into it.