Equality
Equality

Command

Searchable command palette for running commands

View Markdown

Overview

Command is a searchable, keyboard-navigable list for filtering and running commands or selecting from a set of options. It is built on cmdk, so typing in the input filters the list in real time, and the arrow keys plus Enter move through and select items.

It is a compound component: compose a Command from an input, a list, groups, and items. Use it inline (as an embedded searchable list) or wrap it in CommandDialog to present it as a modal command palette.

Usage

Import the parts you need:

import {
  Command,
  CommandInput,
  CommandList,
  CommandEmpty,
  CommandGroup,
  CommandItem,
} from "@eqtylab/equality";

A basic inline command list:

<Command>
  <CommandInput placeholder="Search repositories..." />
  <CommandEmpty>No repositories found.</CommandEmpty>
  <CommandGroup heading="Repositories">
    <CommandItem value="option-1" onSelect={() => handleSelect("option-1")}>
      Option 1
    </CommandItem>
    <CommandItem value="option-2" onSelect={() => handleSelect("option-2")}>
      Option 2
    </CommandItem>
  </CommandGroup>
</Command>

Default

As a Dialog

Wrap the command list in CommandDialog to present it as a modal command palette — commonly opened with a keyboard shortcut such as ⌘K. CommandDialog accepts the same open/onOpenChange props as Dialog, plus an optional title and description (visually part of the dialog header and read by screen readers).

import {
  CommandDialog,
  CommandInput,
  CommandList,
  CommandEmpty,
  CommandGroup,
  CommandItem,
} from "@eqtylab/equality";

const [open, setOpen] = useState(false);

<CommandDialog open={open} onOpenChange={setOpen}>
  <CommandInput placeholder="Type a command or search..." />
  <CommandList>
    <CommandEmpty>No results found.</CommandEmpty>
    <CommandGroup heading="Actions">
      <CommandItem onSelect={() => runAction()}>Run action</CommandItem>
    </CommandGroup>
  </CommandList>
</CommandDialog>;

Slots

Compose a command interface from the following parts:

NameDescription
CommandThe root container that owns filtering and keyboard navigation.
CommandDialogWraps Command in a modal dialog for a command-palette experience.
CommandInputThe search input; typing filters the list. Renders a leading search icon.
CommandListScrollable container for the items.
CommandEmptyContent shown when no items match the current search.
CommandGroupGroups related items under an optional heading.
CommandItemA selectable row. Use value for filtering and onSelect to handle selection.
CommandSeparatorA divider line between groups or items.
CommandShortcutRight-aligned text for showing an item’s keyboard shortcut.

Props

Each part forwards its underlying cmdk props (and className). The most commonly used are listed below.

NameApplies toDescriptionTypeDefault
valueCommandItemThe value used for filtering and passed to onSelect.string
onSelectCommandItemCalled when the item is selected via click or keyboard.(value: string) => void
disabledCommandItemPrevents the item from being selected.booleanfalse
headingCommandGroupOptional label rendered above the group’s items.string
placeholderCommandInputPlaceholder text for the search input.string
openCommandDialogControls whether the dialog is open.boolean
onOpenChangeCommandDialogCalled when the dialog requests to open or close.(open: boolean) => void
titleCommandDialogAccessible dialog title shown in the header.string"Command Palette"
descriptionCommandDialogAccessible dialog description shown in the header.string"Search for a command to run..."