Command

A command palette: type to filter, arrows to move, Enter to run. Items are data rather than children, because filtering has to reorder and hide them.

src/components/ui/command.tsx

About

From the component's own source, where it was written.

A command palette: type to filter, arrows to move, Enter to run.

Items are data rather than children, because filtering has to reorder and hide them — doing that over arbitrary JSX means walking the tree and guessing what is searchable. Groups collapse when every item in them is filtered out.

Install

npx astralyx-ui add command

Usage

import { CommandDialog } from '@/components/ui/command'

<CommandDialog open={open} onOpenChange={setOpen} items={commands} />

Composer

Change the props and the source below follows.

Actions
New project⌘N
Search files⌘P
Copy link
Go to
Documentation
Settings⌘,
Profile
Danger
Delete project
Props
tsx
<CommandList items={commands} />

Examples

Inline

As a modal

API

Generated from the source, so it cannot fall behind the code. One table per exported component, then hooks, functions and types.

CommandList

Extends Omit<ComponentProps<'div'>, 'onSelect'>.

PropTypeDefaultDescription
autoFocusbooleantrue—
itemsCommandItem[]required{ id, label, group?, icon?, shortcut?, keywords?, disabled?, onSelect? }
emptyMessagestring'No results'—
placeholderstring'Type a command or search…'—
onRun(item: CommandItem) => void——

CommandDialog

The palette in a native <dialog>, which is how it is normally used.

Extends ComponentProps<typeof CommandList>.

PropTypeDefaultDescription
openboolean——
onOpenChange(open: boolean) => void——
itemsCommandItem[]required{ id, label, group?, icon?, shortcut?, keywords?, disabled?, onSelect? }
autoFocusboolean——
emptyMessagestring——
placeholderstring——
onRun(item: CommandItem) => void——

Types

CommandItem

A command palette: type to filter, arrows to move, Enter to run.

FieldTypeDescription
idstring—
labelstring—
group?stringSection heading. Groups collapse when every item in them is filtered out.
shortcut?string—
icon?ReactNode—
keywords?stringExtra search terms that are not shown — "find open" makes "Search files" match "open".
disabled?boolean—
onSelect?() => void—

Behaviour

TopicDetailDescription
rankingprefix firstA prefix match on the label ranks above a match anywhere else in the item.