Command
A searchable list of actions, inline or as a ⌘K palette, with pages, shortcuts and highlighted matches.
- Overlay components
- 12 parts
- 8 examples
- vs shadcn/ui
@base-ui/react@tabler/icons-reactcmdk
See it in a real product: Chat Sidebar, Workflow, and Commerce Dashboard
View blockpnpm dlx shadcn@latest add https://hextaui.com/r/command.jsonAdds the component, the HextaUI theme tokens and any HextaUI components it depends on.
Add the theme tokens to your global CSS, if you haven’t yet.
Install the dependencies.
pnpm add @base-ui/react @tabler/icons-react class-variance-authority cmdk cnCopy and paste the following code into your project.
components/ui/command.tsx components/ui/button.tsx lib/motion.ts Update the import paths to match your project setup.
Hotkeys use mod for ⌘ on Apple devices and Ctrl everywhere else. Labels are formatted per platform for you.
Typing filters and ranks items as you go. Groups with no matches disappear, and the list height animates to fit what is left.
Put a <Command /> inside <CommandDialog /> and toggle it with useCommandHotkey. Press ⌘K or Ctrl K. Item shortcuts run while it is open, matches are highlighted, and preserveSearch keeps the query and selection for the next time it opens.
An item with page opens the matching <CommandPage />. The page title appears as a chip in the input, the list slides in from the side, and Backspace on an empty search or Escape goes back.
Long lists scroll inside a capped height. The selected item is always kept in view while you move with the keyboard.
Set shouldFilter={false} and render the results you fetch. <CommandLoading /> waits 150 ms before it appears and then stays at least 300 ms, so fast responses never flash a spinner. Try both latencies.
Headings wrap, long names truncate or wrap as you choose, and shortcuts never get pushed out.
Icons, shortcuts, the page chip and the page slide all follow the reading direction.
| Key | Action |
|---|---|
| ↓ | Selects the next item. |
| ↑ | Selects the previous item. |
| Alt↓ | Jumps to the first item of the next group. |
| Alt↑ | Jumps to the first item of the previous group. |
| Home | Selects the first item. |
| End | Selects the last item. |
| CtrlN | Selects the next item. Ctrl J works too. Turn off with vimBindings. |
| CtrlP | Selects the previous item. Ctrl K works too. Turn off with vimBindings. |
| Enter | Runs the selected item. On a link item, ⌘ Enter or Ctrl Enter opens it in a new tab. |
| Esc | Clears the search first, then goes back one page, then closes the dialog. |
| Backspace | Goes back one page when the search is empty. |
| ⌘P | Any item shortcut runs its item while focus is inside the command menu. |
- The input is a combobox that points at the selected item, so screen readers announce each item as you move.
- A polite live region announces the number of results shortly after you stop typing, and announces the page title when you open or leave a page. Change the wording with
formatResultsandrootTitle. <CommandDialog />has a hidden title and description, traps focus while open and returns it to the trigger when it closes.- Item shortcuts are exposed with
aria-keyshortcuts. - With reduced motion on, items run without the confirm blink and pages fade instead of sliding.
Built on cmdk, with <CommandDialog /> on the Base UI dialog. Parts accept the props of the cmdk part they wrap.
| Prop | Type | Default |
|---|---|---|
labelAccessible name of the menu. | string | "Command menu" |
highlightHighlights the matched letters in each item and dims the rest. | boolean | false |
shouldFilterSet to false to filter and sort the items yourself, for example when results come from a server. | boolean | true |
filterReturns a score from 0 (hidden) to 1 (best match). | (value: string, search: string, keywords?: string[]) => number | – |
valueThe selected item’s value. | string | – |
defaultValue | string | – |
onValueChange | (value: string) => void | – |
loopWrap around at the ends of the list. | boolean | false |
vimBindingsCtrl N, J, P and K navigation. | boolean | true |
disablePointerSelection | boolean | false |
formatResultsText announced to screen readers after typing. | (count: number) => string | "3 results" |
rootTitleAnnounced when you leave the last page and return to the root. | string | "All commands" |
| Attribute | Description |
|---|---|
data-slot="command" | Target the root in CSS. |
data-highlighting | Present while highlight is on and the search is not empty. |
--command-radius | Outer radius. Items derive a concentric radius from it. |
--command-inset | Padding between the list edge and its items. |
| Prop | Type | Default |
|---|---|---|
open | boolean | – |
defaultOpen | boolean | false |
onOpenChange | (open: boolean, details) => void | – |
preserveSearchKeep the dialog mounted so the query, page and selection survive closing. The query is selected when it reopens. | boolean | false |
titleVisually hidden dialog title. | string | "Command menu" |
descriptionVisually hidden dialog description. | string | "Search for a command to run." |
showCloseButton | boolean | false |
classNameApplied to the dialog popup. | string | – |
| Attribute | Description |
|---|---|
data-slot="command-dialog" | The dialog popup. |
data-slot="command-dialog-overlay" | The backdrop. |
data-open | Present on the popup while it is open. |
| Prop | Type | Default |
|---|---|---|
valueControlled search text. | string | – |
onValueChange | (search: string) => void | – |
placeholder | string | – |
clearLabelAccessible name of the clear button. | string | "Clear search" |
backLabelAccessible name of the page chip. | (title: string) => string | (title) => `Back from ${title}` |
| Attribute | Description |
|---|---|
data-slot="command-input" | The input. |
data-slot="command-input-wrapper" | The row holding the icon, input and clear button. |
data-slot="command-clear" | The clear button, shown once you type. |
data-slot="command-page-chip" | The back chip shown on a page. |
| Prop | Type | Default |
|---|---|---|
labelAccessible name of the list. | string | – |
| Attribute | Description |
|---|---|
data-slot="command-list" | The list. |
data-settled | Present once the list has measured itself. The height transition only runs while it is set. |
--cmdk-list-height | Height of the visible items, used to animate the list. |
| Prop | Type | Default |
|---|---|---|
childrenUse the function form to echo the query. | ReactNode | (search: string) => ReactNode | – |
| Attribute | Description |
|---|---|
data-slot="command-empty" | Hidden while a CommandLoading is in the list. |
| Prop | Type | Default |
|---|---|---|
loading | boolean | true |
delayMilliseconds to wait before the spinner shows. | number | 150 |
minDurationMinimum milliseconds the spinner stays once shown. | number | 300 |
labelAccessible label. Defaults to string children. | string | – |
progress | number | – |
| Attribute | Description |
|---|---|
data-slot="command-loading" | The loading row. |
data-pending | Present during the delay, while the row is announced but not yet visible. |
| Prop | Type | Default |
|---|---|---|
heading | ReactNode | – |
valueRequired when there is no heading. | string | – |
forceMountKeep the group visible while filtering. | boolean | false |
| Attribute | Description |
|---|---|
data-slot="command-group" | The group. |
[cmdk-group-heading] | The heading element. |
| Prop | Type | Default |
|---|---|---|
onSelectRuns on click, Enter or the item’s shortcut, after the confirm blink. | (value: string) => void | – |
valueUsed for filtering. Defaults to the item’s text, without the shortcut. | string | – |
keywordsExtra words that match this item. | string[] | – |
disabled | boolean | false |
shortcutA hotkey like "mod+shift+c". Shown on the item and runs it while focus is in the menu. | string | – |
pageOpens the CommandPage with this id instead of running. | string | – |
pageTitleTitle shown in the page chip. Defaults to the value. | string | – |
hrefRenders the item as a link. Enter follows it, ⌘ or Ctrl Enter opens a new tab. | string | – |
renderA link element to render instead, like Next.js <Link />. | ReactElement | – |
confirmBlink the item briefly before running it, so the choice registers. | boolean | true |
forceMountKeep the item visible while filtering. | boolean | false |
| Attribute | Description |
|---|---|
data-slot="command-item" | The item. |
data-selected="true" | Present on the selected item. |
data-disabled="true" | Present on disabled items. |
data-value | The value used for filtering. |
data-confirming | Present during the confirm blink. |
data-page | Present on items that open a page. |
| Prop | Type | Default |
|---|---|---|
idMatches the page prop of the item that opens it. Its groups and items only render while it is the current page. | string | – |
| Prop | Type | Default |
|---|---|---|
hotkeyFormats a hotkey like "mod+k" for the current platform. Children override it. | string | – |
| Attribute | Description |
|---|---|
data-slot="command-shortcut" | The shortcut label. |
| Prop | Type | Default |
|---|---|---|
alwaysRenderKeep it visible while searching. | boolean | false |
| Attribute | Description |
|---|---|
data-slot="command-separator" | The separator. |
| Prop | Type | Default |
|---|---|---|
childrenDefaults to key hints that update on a page. Hidden on touch screens. | ReactNode | – |
| Attribute | Description |
|---|---|
data-slot="command-footer" | The footer. |
| Prop | Type | Default |
|---|---|---|
hotkeyListened for on the whole document. Hotkeys without a modifier are ignored while typing in a field. | string | – |
callback | (event: KeyboardEvent) => void | – |
options.enabled | boolean | true |
Returns whether a loading indicator should be visible, with the same delay and minimum duration as <CommandLoading />. Use it to hide stale results while a request is in flight.
| Prop | Type | Default |
|---|---|---|
loading | boolean | – |
options.delay | number | 150 |
options.minDuration | number | 300 |
useCommandPages()returns{ pages, page, push, pop, reset }to drive pages from your own code.useCommandState(selector)reads cmdk state, such as the search or the filtered count.useHotkeyLabel(hotkey)formats a hotkey for the current platform, like ⌘K or Ctrl+K.
- ButtonButtons in every variant and size, with a built-in loading, success and error flow that skips the spinner for fast requests.
- HotkeyParse, label, announce and match keyboard shortcuts, with ⌘ on Apple platforms and Ctrl everywhere else.
- MotionThe easing curves, durations and reduced-motion check every component animates with, plus hooks for size morphs and sliding highlights.
- SpinnerA loading indicator with Apple-style ticks or a breathing ring that can wait before showing and stay long enough not to flicker.
- Alert dialogA confirmation dialog for destructive or important actions that waits for async work, and becomes a bottom sheet on phones.
- Context menuA menu of actions on right click or long press, with submenus, checkbox and radio items, and hold feedback on touch.
Used in Pro blocks
Blocks that build on Command.
Every block comes with HextaUI Pro, and Prompt Input is free.