Command

A filtered command list — the palette behind ⌘K.

Usage

import { Command } from "@voila.dev/ui/command";
<Command.Root>
	<Command.Input placeholder="Search projects, freelancers…" />
	<Command.List>
		<Command.Empty>No results found.</Command.Empty>
		<Command.Group heading="Projects">
			<Command.Item>
				<CalendarIcon />
				Launch review — Saturday
			</Command.Item>
		</Command.Group>
	</Command.List>
</Command.Root>

A filterable list of commands — the ⌘K palette. It is worth adding once an app has more actions than a person can find by looking, and it is dead weight before that. Command.Dialog is the palette in a modal, which is how it is almost always used; the bare Command embeds the same list in a page or a Popover, which is what Combobox is built on.

Recipes

Command.Dialog takes a title and description that are visually hidden and read by screen readers — the input is the visible cue, but the dialog still needs naming. It is controlled the same way as Dialog, so binding it to ⌘K is a key handler and an open prop.

Group items with Command.Group, and give each a Command.Shortcut where a direct key exists, so the palette teaches the shortcuts rather than replacing them.

API

Command.Root

PropTypeDefault
asChildboolean
childrenReactNode
defaultValuestring | (readonly string[] & string)Optional default item value when it is initially rendered.
disablePointerSelectionbooleanOptionally set to true to disable selection via pointer events.
filterCommandFilterCustom filter function for whether each command menu item should matches the given search query. It should return a number between 0 and 1, with 1 being the best match and 0 being hidden entirely. By default, uses the command-score library.
labelstringAccessible label for this command menu. Not shown visibly.
loopbooleanOptionally set to true to turn on looping around when using the arrow keys.
onValueChange((value: string) => void)Event handler called when the selected item of the menu changes.
shouldFilterbooleanOptionally set to false to turn off the automatic filtering and sorting. If false, you must conditionally render valid items based on the search query yourself.
valuestringOptional controlled state of the selected command menu item.
vimBindingsbooleanSet to false to disable ctrl+n/j/p/k shortcuts. Defaults to true.

Plus the DOM props of the element it renders. Source: command/components/command-root.tsx.

The undescribed props here come from cmdk, which this is built on; its documentation covers filter, shouldFilter, loop and the others.

Command.Dialog

PropTypeDefault
childrenReactNoderequiredThe Command tree: input, list, groups and items.
classNamestringClasses for the dialog panel.
descriptionstring"Search for a command to run..."Accessible description, also visually hidden.
showCloseButtonbooleanfalseDraws the X in the corner.
titlestring"Command Palette"Accessible name of the dialog. Visually hidden — the input is the visible cue.
actionsRefRefObject<DialogRootActions | null>A ref to imperative actions.
defaultOpenbooleanWhether the dialog is initially open. To render a controlled dialog, use the open prop instead.
defaultTriggerIdstring | nullID of the trigger that the dialog is associated with. This is useful in conjunction with the defaultOpen prop to create an initially open dialog.
disablePointerDismissalbooleanWhether to prevent the dialog from closing on outside presses. For non-modal dialogs, this also prevents the dialog from closing when focus moves outside of it.
handleDialogHandle<unknown>A handle to associate the dialog with a trigger. If specified, allows external triggers to control the dialog's open state. Can be created with the Dialog.createHandle() method.
modal"trap-focus" | booleanDetermines if the dialog enters a modal state when open. When modal is true or 'trap-focus', render <Dialog.Close> inside <Dialog.Popup> so touch screen readers can escape the popup.
onOpenChange((open: boolean, eventDetails: DialogRootChangeEventDetails) => void)Event handler called when the dialog is opened or closed.
onOpenChangeComplete((open: boolean) => void)Event handler called after any animations complete when the dialog is opened or closed.
openbooleanWhether the dialog is currently open.
triggerIdstring | nullID of the trigger that the dialog is associated with. This is useful in conjunction with the open prop to create a controlled dialog. There's no need to specify this prop when the dialog is uncontrolled (that is, when the open prop is not set).

Plus the DOM props of the element it renders. Source: command/components/command-dialog.tsx.

Command.Empty

PropTypeDefault
asChildboolean
childrenReactNode

Plus the DOM props of the element it renders. Source: command/components/command-empty.tsx.

Command.Group

PropTypeDefault
asChildboolean
childrenReactNode
forceMountbooleanWhether this group is forcibly rendered regardless of filtering.
headingReactNodeOptional heading to render for this group.
valuestringIf no heading is provided, you must provide a value that is unique for this group.

Plus the DOM props of the element it renders. Source: command/components/command-group.tsx.

Command.Input

PropTypeDefault
asChildboolean
onValueChange((search: string) => void)Event handler called when the search value changes.
valuestringOptional controlled state for the value of the search input.

Plus the DOM props of the element it renders. Source: command/components/command-input.tsx.

Command.Item

PropTypeDefault
asChildboolean
childrenReactNode
disabledbooleanWhether this item is currently disabled.
forceMountbooleanWhether this item is forcibly rendered regardless of filtering.
keywordsstring[]Optional keywords to match against when filtering.
onSelect((value: string) => void)Event handler for when this item is selected, either via click or keyboard selection.
valuestringA unique value for this item. If no value is provided, it will be inferred from children or the rendered textContent. If your textContent changes between renders, you must provide a stable, unique value.

Plus the DOM props of the element it renders. Source: command/components/command-item.tsx.

Command.List

PropTypeDefault
asChildboolean
childrenReactNode
labelstringAccessible label for this List of suggestions. Not shown visibly.

Plus the DOM props of the element it renders. Source: command/components/command-list.tsx.

Command.Separator

PropTypeDefault
alwaysRenderbooleanWhether this separator should always be rendered. Useful if you disable automatic filtering.
asChildboolean

Plus the DOM props of the element it renders. Source: command/components/command-separator.tsx.

Command.Shortcut

PropTypeDefault
keysreadonly string[]Render each key as a small Kbd chip. Omit it and children are shown as plain text.

Plus the DOM props of the element it renders. Source: command/components/command-shortcut.tsx.

Combobox · Dialog · Kbd · DropdownMenu