- Accordion
- Alert
- Alert Dialog
- Aspect Ratio
- Attachment
- Autocomplete
- Avatar
- Badge
- Breadcrumb
- Bubble
- Button
- Calendar
- Card
- Carousel
- Chart
- Checkbox
- Checkbox Group
- Collapsible
- Combobox
- Command
- Context Menu
- Date Picker
- Dialog
- Drawer
- Dropdown Menu
- Empty
- Field
- Fieldset
- Form
- Frame
- Group
- Input
- Input Group
- Kbd
- Label
- Menu
- Menubar
- Message
- Meter
- Number Field
- OTP Field
- Pagination
- Popover
- Preview Card
- Progress
- Questionnaire
- Radio Group
- Scroll Area
- Select
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Spinner
- Switch
- Table
- Tabs
- Textarea
- Toggle
- Toggle Group
- Toolbar
- Tooltip
- Artifact
- Audio Player
- Canvas
- Chain of Thought
- Checkpoint
- Code Block
- Commit
- Connection
- Context
- Controls
- Edge
- Environment Variables
- Mic Selector
- Model Selector
- Node
- Node Toolbar
- Open in Chat
- Panel
- Plan
- Prompt Input
- Queue
- Reasoning
- Sandbox
- Schema Display
- Shimmer
- Snippet
- Sources
- Speech Input
- Stack Trace
- Suggestion
- Tool
- Transcription
- Web Preview
Command
A command palette component built with cmdk and Dialog for searching and executing commands.
Command Palette
Search for a command to run...
"use client";
import { useState } from "react";
import { Button } from "@/components/ui/button";
import {
Command,
CommandDialog,
CommandEmpty,
CommandGroup,
CommandInput,
CommandItem,
CommandList,
CommandSeparator,
CommandShortcut,
} from "@/components/ui/command";
import { Kbd } from "@/components/ui/kbd";
export default function Particle() {
const [open, setOpen] = useState(false);
return (
<>
<Button onClick={() => setOpen(true)} variant="outline">
Open Command Palette
<Kbd className="-me-1">⌘K</Kbd>
</Button>
<CommandDialog onOpenChange={setOpen} open={open}>
<Command>
<CommandInput placeholder="Search..." />
<CommandList>
<CommandEmpty>No results found.</CommandEmpty>
<CommandGroup heading="Suggestions">
<CommandItem value="linear">Linear</CommandItem>
<CommandItem value="figma">Figma</CommandItem>
<CommandItem value="slack">Slack</CommandItem>
</CommandGroup>
<CommandSeparator />
<CommandGroup heading="Settings">
<CommandItem value="profile">
Profile
<CommandShortcut>⌘P</CommandShortcut>
</CommandItem>
<CommandItem value="billing">
Billing
<CommandShortcut>⌘B</CommandShortcut>
</CommandItem>
</CommandGroup>
</CommandList>
</Command>
</CommandDialog>
</>
);
}
Installation
pnpm dlx shadcn@latest add @frontal-labs/command
Usage
import {
Command,
CommandDialog,
CommandEmpty,
CommandGroup,
CommandInput,
CommandItem,
CommandList,
CommandSeparator,
CommandShortcut,
} from "@/components/ui/command";CommandDialog renders the dialog itself, so it is controlled with open and
onOpenChange. Compose the palette from Command and its parts inside it:
const [open, setOpen] = useState(false);
return (
<>
<Button onClick={() => setOpen(true)} variant="outline">
Open Command Palette
</Button>
<CommandDialog onOpenChange={setOpen} open={open}>
<Command>
<CommandInput placeholder="Search..." />
<CommandList>
<CommandEmpty>No results found.</CommandEmpty>
<CommandItem value="linear">Linear</CommandItem>
<CommandItem value="figma">Figma</CommandItem>
<CommandItem value="slack">Slack</CommandItem>
</CommandList>
</Command>
</CommandDialog>
</>
);API Reference
Command
The root component. It's a styled wrapper around cmdk's Command, which owns the
filtering and keyboard navigation.
| Prop | Type | Description |
|---|---|---|
value | string | The value of the currently selected item |
onValueChange | (value: string) => void | Callback fired when the selected item changes |
shouldFilter | boolean | Set to false to filter items yourself |
className | string | Additional CSS classes to apply to the component |
...props | React.ComponentProps<typeof CommandPrimitive> | All cmdk Command props are supported |
CommandDialog
Renders the command palette inside a Dialog. It provides the dialog root, a
visually hidden header for accessibility, and the dialog content — so it is used
directly rather than composed with a separate trigger and popup. Open it from any
button by controlling open.
| Prop | Type | Default | Description |
|---|---|---|---|
open | boolean | - | Controls whether the dialog is open |
onOpenChange | function | - | Callback fired when the open state changes |
title | string | "Command Palette" | Accessible title, rendered visually hidden |
description | string | "Search for a command to run..." | Accessible description, rendered visually hidden |
showCloseButton | boolean | false | Whether the dialog renders a close button |
dark | boolean | true | Renders the surface with the dark palette; pass false to follow the ambient theme instead |
className | string | - | Additional CSS classes for the dialog content |
CommandInput
The search input field with an integrated search icon.
| Prop | Type | Description |
|---|---|---|
placeholder | string | The placeholder text for the input |
value | string | The controlled search value |
onValueChange | (value: string) => void | Callback fired when the search value changes |
className | string | Additional CSS classes to apply to the component |
...props | cmdk Command.Input props | All cmdk input props are supported |
CommandList
A scrollable container for command items.
| Prop | Type | Description |
|---|---|---|
className | string | Additional CSS classes to apply to the component |
...props | cmdk Command.List props | All cmdk list props are supported |
CommandEmpty
Displays a message when no results are found. Render it inside CommandList.
| Prop | Type | Description |
|---|---|---|
className | string | Additional CSS classes to apply to the component |
...props | cmdk Command.Empty props | All cmdk empty props are supported |
CommandGroup
Groups related command items together. Pass heading to label the group.
| Prop | Type | Description |
|---|---|---|
heading | React.ReactNode | The label rendered above the group |
value | string | The value used when filtering the group |
className | string | Additional CSS classes to apply to the component |
...props | cmdk Command.Group props | All cmdk group props are supported |
CommandItem
An individual selectable command item.
| Prop | Type | Description |
|---|---|---|
value | string | The value of the item, used for filtering |
onSelect | (value: string) => void | Callback fired when the item is selected |
disabled | boolean | Whether the item is disabled |
className | string | Additional CSS classes to apply to the component |
...props | cmdk Command.Item props | All cmdk item props are supported |
CommandSeparator
A visual separator between command groups or items.
| Prop | Type | Description |
|---|---|---|
className | string | Additional CSS classes to apply to the component |
...props | cmdk Command.Separator props | All cmdk separator props are supported |
CommandShortcut
Displays keyboard shortcuts in a styled span element.
| Prop | Type | Description |
|---|---|---|
className | string | Additional CSS classes to apply to the component |
...props | React.ComponentProps<'span'> | All standard span attributes are supported |
Examples
With Keyboard Shortcut
You can add a keyboard shortcut to open the command palette:
React.useEffect(() => {
const down = (e: KeyboardEvent) => {
if (e.key === "k" && (e.metaKey || e.ctrlKey)) {
e.preventDefault();
setOpen((open) => !open);
}
};
document.addEventListener("keydown", down);
return () => document.removeEventListener("keydown", down);
}, []);With Grouped Items
Use CommandGroup with a heading for each section, and CommandSeparator
between them:
import { Fragment } from "react"
const groups = [
{
heading: "Suggestions",
items: [
{ value: "linear", label: "Linear" },
{ value: "figma", label: "Figma" },
],
},
{
heading: "Commands",
items: [
{ value: "clipboard", label: "Clipboard History" },
{ value: "settings", label: "System Preferences" },
],
},
]
<Command>
<CommandInput placeholder="Search..." />
<CommandList>
<CommandEmpty>No results found.</CommandEmpty>
{groups.map((group, index) => (
<Fragment key={group.heading}>
<CommandGroup heading={group.heading}>
{group.items.map((item) => (
<CommandItem key={item.value} value={item.value}>
{item.label}
</CommandItem>
))}
</CommandGroup>
{index < groups.length - 1 && <CommandSeparator />}
</Fragment>
))}
</CommandList>
</Command>With Shortcuts
CommandShortcut aligns a keyboard hint to the end of an item:
<CommandItem value="new-file">
New File
<CommandShortcut>⌘N</CommandShortcut>
</CommandItem>Standalone Command (Without Dialog)
You can use the Command component without a dialog wrapper:
<Command className="rounded-md ring-1 ring-foreground/10">
<CommandInput placeholder="Type a command..." />
<CommandList>
<CommandEmpty>No results found.</CommandEmpty>
<CommandItem value="linear">Linear</CommandItem>
<CommandItem value="figma">Figma</CommandItem>
</CommandList>
</Command>