command
A searchable dropdown field powered by cmdk. Unlike combobox (which uses a popover), command renders an inline command palette with keyboard navigation.
Note: The
commandfield requires the consumer to providecmdk-based components. Install them withnpx shadcn@latest add command.
Basic Usage
FormBuilder.create('search-form')
.addField('framework', (f) =>
f
.type('command')
.label('Framework')
.options([
{ label: 'React', value: 'react' },
{ label: 'Vue', value: 'vue' },
{ label: 'Svelte', value: 'svelte' },
{ label: 'Angular', value: 'angular' },
{ label: 'Solid', value: 'solid' },
])
.required(),
)
.addStep('main', ['framework'])
.build();
Props
| Prop | Type | Default | Description |
|---|---|---|---|
options | Option[] | Required | Array of { label, value, icon? } |
placeholder | string | "Select..." | Text shown when no value selected |
searchPlaceholder | string | "Search..." | Placeholder in the search input |
emptyText | string | "No results found." | Text shown when search has no matches |
command vs combobox
Both fields use cmdk components under the hood. The difference is presentation:
| Feature | command | combobox |
|---|---|---|
| Container | Inline (always visible) | Popover (click to open) |
| Search | Always accessible | Accessible after opening |
| Use case | Primary selection, prominent placement | Space-constrained, standard form field |
Both support icons on options, custom search/empty text, and the same validation rules.
Required Components
The command field requires these components in your registry:
Command,CommandInput,CommandList,CommandEmpty,CommandGroup,CommandItemFormField,FormControl,Field,FieldLabel,FieldDescription,FieldError
Install the cmdk components:
npx shadcn@latest add command
With Icons
import { Globe, Zap, Palette } from 'lucide-react';
.addField('framework', (f) => f.type('command').label('Framework')
.options([
{ label: 'React', value: 'react', icon: <Globe /> },
{ label: 'Vue', value: 'vue', icon: <Zap /> },
{ label: 'Svelte', value: 'svelte', icon: <Palette /> },
])
)
TypeScript
interface CommandFieldProps extends BaseFieldProps {
type: 'command';
options: Option[];
schema: z.ZodType | ValidationRules;
placeholder?: string;
searchPlaceholder?: string;
emptyText?: string;
}
Related
- combobox — Popover-based searchable dropdown
- select — Standard dropdown without search
- Component System — How to provide cmdk components