Command

React Command components are used to build fast, composable, and accessible command menus. They are essential for creating command palettes, search dialogs, and navigation shortcuts that improve user productivity.

This Command component is built with React and React Aria Components, ensuring high accessibility and smooth keyboard navigation. It supports filtering, grouping, keyboard shortcuts, and can be easily integrated into modal dialogs.

Installation

Install the component using the Tailgrids CLI.

npx @tailgrids/cli add command

Anatomy

Import the component and pass the required props.

import {
  Command,
  CommandDialog,
  CommandEmpty,
  CommandGroup,
  CommandInput,
  CommandItem,
  CommandList,
  CommandSeparator,
  CommandShortcut
} from "@/registry/core/command";

export function CommandDemo() {
  return (
    <Command className="rounded-lg border shadow-md">
      <CommandInput placeholder="Type a command or search..." />
      <CommandList>
        <CommandEmpty>No results found.</CommandEmpty>
        <CommandGroup heading="Suggestions">
          <CommandItem>
            <Calendar className="mr-2 h-4 w-4" />
            <span>Calendar</span>
          </CommandItem>
          <CommandItem>
            <Smile className="mr-2 h-4 w-4" />
            <span>Search Emoji</span>
          </CommandItem>
          <CommandItem>
            <Calculator className="mr-2 h-4 w-4" />
            <span>Calculator</span>
          </CommandItem>
        </CommandGroup>
        <CommandSeparator />
        <CommandGroup heading="Settings">
          <CommandItem>
            <User className="mr-2 h-4 w-4" />
            <span>Profile</span>
            <CommandShortcut>⌘P</CommandShortcut>
          </CommandItem>
          <CommandItem>
            <CreditCard className="mr-2 h-4 w-4" />
            <span>Billing</span>
            <CommandShortcut>⌘B</CommandShortcut>
          </CommandItem>
          <CommandItem>
            <Settings className="mr-2 h-4 w-4" />
            <span>Settings</span>
            <CommandShortcut>⌘S</CommandShortcut>
          </CommandItem>
        </CommandGroup>
      </CommandList>
    </Command>
  );
}

Examples

Dialog

The CommandDialog component allows you to wrap the command menu in a modal dialog.

Press J

Complex Menu

An example of a more complex command menu with icons, descriptions, and grouped actions. Note the use of textValue for filtering.

A search-centric example focused on finding files and folders with metadata.

API Reference

Command

The root component of the command menu.

PropTypeDefaultDescription
classNamestring-Additional CSS classes to apply to the command menu.
filterfunction-Custom filter function for items. Defaults to contains with base sensitivity.
labelstring-Accessible label for the command menu.
shouldFilterbooleantrueWhether the command menu should filter items.

See useFilter for more information on filtration.

CommandInput

The search input field for the command menu.

PropTypeDefaultDescription
classNamestring-Additional CSS classes to apply to the command input.
placeholderstring-Placeholder text for the input.
disabledbooleanfalseDisables interaction with the input.

CommandList

The container for the command items. It automatically detects and renders CommandEmpty if no results are found.

PropTypeDefaultDescription
classNamestring-Additional CSS classes to apply to the command list.
renderEmptyState(items) => ReactNode-Custom render function for the empty state.

CommandDialog

A command menu wrapped in a modal dialog.

PropTypeDefaultDescription
classNamestring-Additional CSS classes to apply to the command menu.
isOpenboolean-Controls the open state of the dialog.
onOpenChangefunction-Event handler called when the open state changes.

NOTE: CommandDialog includes built-in keyboard shortcuts: ⌘J (Mac) or Ctrl+J (Windows/Linux) to open, and Escape to close.

CommandEmpty

Displays a message when no search results are found.

PropTypeDefaultDescription
classNamestring-Additional CSS classes to apply to the command menu.

CommandGroup

Groups related command items under a heading.

PropTypeDefaultDescription
headingReactNode-Optional heading for the group.
classNamestring-Additional CSS classes to apply to the command group.

CommandItem

An individual item in the command menu.

PropTypeDefaultDescription
classNamestring-Additional CSS classes to apply to the command item.
disabledbooleanfalseDisables the item.
onSelectfunction-Event handler called when the item is selected.
valuestring-Unique value for the item.
textValuestring-[Required] The text representation used for filtering when children contain complex elements (icons, spans, etc).

CommandShortcut

Displays a keyboard shortcut hint for a command item.

PropTypeDefaultDescription
classNamestring-Additional CSS classes to apply to the command menu.

CommandSeparator

A visual divider between items or groups.

PropTypeDefaultDescription
classNamestring-Additional CSS classes to apply to the command menu.

Accessibility

  • Keyboard Navigation: Use arrow keys to navigate between items.
  • Filtering: Items are automatically filtered based on input.
  • Screen Reader Support: Properly labeled with ARIA attributes.