Command
A searchable command palette, opened with ⌘K.
A searchable command palette, opened with ⌘K.
The same component at all four levels. Pick the one that fits your project; they share tokens, so they mix.
npm i junco @junco/tailwindimport { CommandDialog, CommandInput, CommandList, CommandEmpty, CommandGroup, CommandItem, CommandShortcut } from "junco";
<CommandDialog>
<CommandInput placeholder="Search…" />
<CommandList>
<CommandEmpty>No results.</CommandEmpty>
<CommandGroup heading="Pages">
<CommandItem onSelect={() => go("/settings")}>
Settings <CommandShortcut>⌘,</CommandShortcut>
</CommandItem>
</CommandGroup>
</CommandList>
</CommandDialog>CommandDialog listens for ⌘K / Ctrl+K on its own. This site already uses ⌘K for search, so this demo sets shortcut="j": click the button or press ⌘J / Ctrl+J. Esc returns focus to where you were.
Command also works on the page, for pickers and searchable lists.
CommandDialog#Command inside a Dialog, with a keyboard shortcut. Also takes every Command prop.
opendefaultOpenonOpenChangeshortcuttitledescriptionclassNames| Prop | Type | Default |
|---|---|---|
openControlled open state. | boolean | – |
defaultOpenInitial open state when uncontrolled. | boolean | false |
onOpenChangeCalled when it opens or closes, including from the shortcut. | (open: boolean) => void | – |
shortcutLetter that toggles it with ⌘ or Ctrl. null turns the shortcut off. | string | null | "k" |
titleDialog title for screen readers. | string | "Command palette" |
descriptionDialog description for screen readers. | string | "Search for a command to run." |
classNamesClass overrides for the dialog and the list. | { content?, command? } | – |
Command#The searchable list (cmdk).
filtershouldFilterloop| Prop | Type | Default |
|---|---|---|
filterCustom ranking. Return 0 to hide an item. | (value, search) => number | – |
shouldFilterSet false when you filter on the server. | boolean | true |
loopArrow keys wrap from the last item to the first. | boolean | false |
CommandItem#onSelectvaluekeywordsdisabled| Prop | Type | Default |
|---|---|---|
onSelectRuns on click or Enter. | (value: string) => void | – |
valueText matched by search. Defaults to the item's text. | string | – |
keywordsExtra words that should match this item. | string[] | – |
disabledShown but not selectable. | boolean | – |
| Key | Action |
|---|---|
| ⌘K | Opens or closes CommandDialog (Ctrl+K on Windows and Linux). |
| ↓↑ | Moves between results. |
| Enter | Runs the highlighted result. |
| Esc | Closes the dialog and returns focus. |