Command
A fast, composable command menu. The highlight glides between results and the list height eases as you filter.
Playground
Tweak the props, the preview and the code follow.
<Command loop>
<CommandInput placeholder="Type a command or search…" />
<CommandList>
<CommandEmpty>No results.</CommandEmpty>
<CommandGroup heading="Suggestions">
<CommandItem><Calendar /> Calendar</CommandItem>
<CommandItem><Smile /> Search emoji</CommandItem>
</CommandGroup>
<CommandSeparator />
<CommandGroup heading="Settings">
<CommandItem>
<User /> Profile
<CommandShortcut>⌘P</CommandShortcut>
</CommandItem>
</CommandGroup>
</CommandList>
</Command>Installation
npx @plumsydev/plum-ui add commandAlso pulls in dialog automatically.
Usage
import {
Command,
CommandEmpty,
CommandGroup,
CommandInput,
CommandItem,
CommandList,
CommandShortcut,
} from "@/components/ui/command"<Command>
<CommandInput placeholder="Search…" />
<CommandList>
<CommandEmpty>No results.</CommandEmpty>
<CommandGroup heading="Suggestions">
<CommandItem>Calendar</CommandItem>
<CommandItem>
Settings <CommandShortcut>⌘,</CommandShortcut>
</CommandItem>
</CommandGroup>
</CommandList>
</Command>Examples
Command palette
CommandDialog wraps the menu in a dialog anchored near the top of the screen. Try ⌘J.
Nested pages
Drill into sub-pages with breadcrumbs. Backspace on an empty input goes back.
API Reference
Command
| Prop | Type | Default |
|---|---|---|
valueControlled selected item value. | string | — |
onValueChangeCalled when the highlighted item changes. | (value: string) => void | — |
shouldFilterSet to false to filter items yourself (e.g. async search). | boolean | true |
loopWrap keyboard navigation from last to first item. | boolean | false |
CommandDialog
Accepts every Dialog root prop.
| Prop | Type | Default |
|---|---|---|
titleAccessible title, visually hidden. | string | "Command palette" |
descriptionAccessible description, visually hidden. | string | — |
showCloseButtonShow the dialog close button. | boolean | false |
CommandItem
| Prop | Type | Default |
|---|---|---|
valueValue used for filtering. Defaults to the text content. | string | — |
keywordsExtra search terms that match this item. | string[] | — |
onSelectCalled on click or Enter. | (value: string) => void | — |
disabledMake the item unselectable. | boolean | false |
Notes
- Bind the palette to a global shortcut with a
keydownlistener ondocument— see the dialog example.