Command

Fast, composable command palette built on cmdk with search, groups, and shortcuts.

<Command className="rounded-lg border md:min-w-[450px]">  <CommandInput placeholder="Type a command or search..." />  <CommandList>    <CommandEmpty>No results found.</CommandEmpty>    <CommandGroup heading="Suggestions">      <CommandItem>        <CalendarIcon />        <span>Calendar</span>      </CommandItem>      <CommandItem>        <Smiley />        <span>Search Emoji</span>      </CommandItem>      <CommandItem>        <Calculator />        <span>Calculator</span>      </CommandItem>    </CommandGroup>    <CommandSeparator />    <CommandGroup heading="Settings">      <CommandItem>        <User />        <span>Profile</span>        <CommandShortcut>⌘P</CommandShortcut>      </CommandItem>      <CommandItem>        <CreditCard />        <span>Billing</span>        <CommandShortcut>⌘B</CommandShortcut>      </CommandItem>      <CommandItem>        <Gear />        <span>Settings</span>        <CommandShortcut>⌘S</CommandShortcut>      </CommandItem>    </CommandGroup>  </CommandList></Command>

Usage

import {
  Command,
  CommandDialog,
  CommandEmpty,
  CommandGroup,
  CommandInput,
  CommandItem,
  CommandList,
  CommandSeparator,
  CommandShortcut,
} from "@reva/ui";

CommandShortcut is a styled <span> that renders trailing keystroke hints (⌘K, ⌘P, …). A dedicated Kbd primitive ships in Wave 6; until then, prefer CommandShortcut for consistency with the palette chrome.

Composition

Use the following composition to build a Command:

Command
├── CommandInput
└── CommandList
    ├── CommandEmpty
    ├── CommandGroup (heading="Suggestions")
    │   ├── CommandItem
    │   ├── CommandItem
    │   └── CommandItem
    ├── CommandSeparator
    └── CommandGroup (heading="Settings")
        ├── CommandItem
        │   └── CommandShortcut
        ├── CommandItem
        │   └── CommandShortcut
        └── CommandItem
            └── CommandShortcut

Examples

Command dialog

Wrap the palette in CommandDialog for a centred modal (⌘K pattern). Drive open from a useEffect listener so users can summon the palette from anywhere.

import { useEffect, useState } from "react";
import {
  CommandDialog,
  CommandEmpty,
  CommandGroup,
  CommandInput,
  CommandItem,
  CommandList,
} from "@reva/ui";

export function CommandPalette() {
  const [open, setOpen] = useState(false);

  useEffect(() => {
    const down = (event: KeyboardEvent) => {
      if (event.key === "k" && (event.metaKey || event.ctrlKey)) {
        event.preventDefault();
        setOpen((value) => !value);
      }
    };
    document.addEventListener("keydown", down);
    return () => document.removeEventListener("keydown", down);
  }, []);

  return (
    <CommandDialog open={open} onOpenChange={setOpen}>
      <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>
      </CommandList>
    </CommandDialog>
  );
}

Props

Command (root)

Wraps cmdk's Command.Root. Common props:

PropTypeDefaultDescription
valuestringControlled active item value.
onValueChange(value: string) => voidControlled active item handler.
filter(value: string, search: string) => numberCustom fuzzy filter; return 0 to hide an item.
shouldFilterbooleantrueDisable to drive results from your own data layer.
loopbooleanfalseWrap arrow-key navigation between first and last items.

CommandInput

PropTypeDefaultDescription
placeholderstringPlaceholder text for the search input.
valuestringControlled search query.
onValueChange(value: string) => voidControlled search handler.

CommandItem

PropTypeDefaultDescription
valuestringOverride the matchable string (defaults to the rendered text).
disabledbooleanfalsePrevents selection and excludes the item from filtering.
onSelect(value: string) => voidFires when the item is activated.

CommandDialog

PropTypeDefaultDescription
openbooleanControlled open state.
onOpenChange(open: boolean) => voidControlled open handler.
titlestring"Command Palette"Screen-reader title for the dialog.
descriptionstring"Search for a command to run..."Screen-reader description.
showCloseButtonbooleanfalseRender the dialog's built-in close button.

On this page