Skip to main content
Command is the root wrapper for the entire command menu. Render it inline in your UI, or use Command.Dialog to render it in an overlay. It manages all internal state including the current search query, selected item, and filtered results.
Data attribute: [cmdk-root]
All item values are trimmed with String.trim() before being used for filtering or comparison.

Props

string
Accessible label for the command menu. Rendered as a visually hidden <label> element associated with the input. Use this to describe the purpose of the menu to screen reader users.
boolean
default:"true"
Set to false to disable automatic filtering and sorting. When disabled, you are responsible for conditionally rendering items based on the current search query. Useful for server-side filtering or virtualized lists.
(value: string, search: string, keywords?: string[]) => number
Custom filter function used to rank each item against the search query. Return a number between 0 and 1, where 1 is the best match and 0 hides the item entirely. Defaults to the built-in command-score algorithm.
string
The value of the item that is selected when the menu first renders. Has no effect if value is provided (controlled mode).
string
The controlled value of the currently selected item. Use together with onValueChange to manage selection state externally.
(value: string) => void
Callback fired when the selected item changes. Receives the value string of the newly selected item.
boolean
default:"false"
When true, keyboard navigation wraps around: pressing ArrowDown on the last item moves focus to the first item, and vice versa.
boolean
default:"false"
When true, moving the pointer over an item does not select it. Selection only changes through keyboard navigation or clicks.
boolean
default:"true"
When true, enables Ctrl+N / Ctrl+J to move down and Ctrl+P / Ctrl+K to move up, mirroring common Vim-style navigation bindings.

Keyboard navigation

Examples

Controlled selection

Pass value and onValueChange to control which item is selected:

Custom filter function

Replace the default scoring algorithm with your own logic. The function receives the item’s value, the current search query, and returns a score between 0 (hidden) and 1 (best match):

Custom filter with keywords

The filter function also receives a third keywords argument — the array passed to each Command.Item. Use it to match against aliases:

Disable automatic filtering

Set shouldFilter={false} to take full control of which items are rendered. Useful for server-side search or when you have too many items to filter in the browser:

Looping navigation

Enable wrap-around keyboard navigation so pressing ArrowDown on the last item returns to the first: