Skip to content
Esc
↑↓navigate↵open⌘Jpreview
On this page

Command for Astro

Searchable Astro command lists for navigation and page actions.

API Reference
Suggestions
Calendar
Search Emoji
Calculator
Settings
Profile ⌘P
Billing ⌘B
Settings ⌘S

Installation

bunx --bun shadcn@latest add @gnostic/command

Usage

import {
    Command,
    CommandDialog,
    CommandEmpty,
    CommandGroup,
    CommandInput,
    CommandItem,
    CommandList,
    CommandSeparator,
    CommandShortcut,
} from "@/components/ui/command"
<Command class="ring-foreground/10 max-w-sm rounded-lg ring-1">
  <CommandInput placeholder="Search commands..." />
  <CommandList>
    <CommandEmpty>No results found.</CommandEmpty>
    <CommandGroup heading="Suggestions">
      <CommandItem>Calendar</CommandItem>
      <CommandItem>Search Emoji</CommandItem>
      <CommandItem>Calculator</CommandItem>
    </CommandGroup>
    <CommandSeparator />
    <CommandGroup heading="Settings">
      <CommandItem>Profile</CommandItem>
      <CommandItem>Billing</CommandItem>
      <CommandItem>Settings</CommandItem>
    </CommandGroup>
  </CommandList>
</Command>

Composition

Arrange the parts as shown for a Command:

Command
├── CommandInput
└── CommandList
    ├── CommandEmpty
    ├── CommandGroup
    │   ├── CommandItem
    │   └── CommandItem
    ├── CommandSeparator
    └── CommandGroup
        ├── CommandItem
        └── CommandItem

Examples

Basic

A simple command menu in a dialog.

Quick actions
Send email ⌘E
Deploy project ⌘D
Open settings ⌘,
Keyboard shortcuts ?

With Groups

A command menu with groups, icons and separators.

Suggestions
Calendar
Notes
Projects
Account
Profile
Billing
Settings
API Keys

Many Groups & Items

Scrollable command menu with multiple items.

Recent
Recent search 1
Recent search 2
Recent search 3
Recent search 4
Recent search 5
Recent search 6
Recent search 7
Recent search 8
Recent search 9
Recent search 10
Recent search 11
Recent search 12
Recent search 13
Recent search 14
Recent search 15
Recent search 16
Recent search 17
Recent search 18

API Reference

CommandProps

PropType
label?string

Accessible label announced for the command input

Typestring
defaultValue?string

Initial active item value

Typestring
defaultSearch?string

Initial search input value

Typestring
shouldFilter?boolean

Disable built-in filtering and sorting

Typeboolean
loop?boolean

Wrap arrow-key navigation

Typeboolean
disablePointerSelection?boolean

Disable pointer-move selection

Typeboolean
vimBindings?boolean

Enable ctrl+j/k/n/p shortcuts

Typeboolean
Defaulttrue

See the data-slot docs for more information on interactivity.

Events

Dispatch these events on the command root. The root emits the outbound events.

Outbound events

Event Detail
command:change { value: string | null }
command:search-change { search: string }
command:select { value: string }

Inbound events

Event Detail
command:set { value?: string | null, search?: string }

Read the installed source for the complete prop types.

When to use Command

Use Command for a labelled list of actions that can be filtered. Group related commands and give each item a useful search value. CommandDialog places the list in an existing modal dialog.

Keyboard and behavior

The data-slot controller handles list navigation and selection. Your code handles the selected action. A displayed shortcut does not register a keyboard listener. If you add a global shortcut, avoid conflicts with text input and browser commands.

Theme and layout

Shared popover colors and item focus styles keep the list readable in both modes. Keep descriptions brief and test an empty search. Large or remote command sets need their own data and loading logic.