Command

Command menu for search and quick actions.

About

The Command component uses the cmdk component by Dip.

Installation

pnpm dlx cubix@latest add command --base aria

Usage

Import
import {
  Command,
  CommandDialog,
  CommandEmpty,
  CommandGroup,
  CommandInput,
  CommandItem,
  CommandList,
  CommandSeparator,
  CommandShortcut,
} from "@/components/cubix/command"
Example
<Command className="max-w-sm rounded-lg border">
  <CommandInput placeholder="Type a command or search..." />
  <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

Use the following composition to build a Command:

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

Examples

Basic

A simple command menu in a dialog.

Command Palette

Search for a command to run...

Shortcuts

Command Palette

Search for a command to run...

Groups

A command menu with groups, icons and separators.

Command Palette

Search for a command to run...

Scrollable

Scrollable command menu with multiple items.

Command Palette

Search for a command to run...

API Reference

Note: See the cmdk documentation for more information.

Command

The root that provides search context to input, list, and items.

PropTypeDefaultDescription
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).
childrenReact.ReactNode-CommandInput and CommandList.

CommandDialog

Wraps Command in a dialog for a palette overlay.

PropTypeDefaultDescription
openboolean-Controlled open state of the dialog.
onOpenChange(open: boolean) => void-Called when the open state changes.
titlestring"Command Palette"Accessible title, visually hidden.
descriptionstring"Search for a command to run..."Accessible description, visually hidden.
showCloseButtonbooleanfalseShow the dialog close button.

CommandInput

PropTypeDefaultDescription
placeholderstring-Placeholder text for the search field.
valuestring-Controlled search value.
onValueChange(search: string) => void-Called when the search value changes.

CommandGroup

PropTypeDefaultDescription
headingstring-Optional group label.

CommandItem

PropTypeDefaultDescription
disabledboolean-Disable the item.
onSelect(value: string) => void-Called when the item is selected.
valuestring-Search value. Defaults to the item text.