Clidey UXDocs

Command

Command is a keyboard-first command palette built on the cmdk library. Use it for global search, quick navigation, or any fuzzy-search interface.

Interactive example#

Command · Live example

Nothing selected

Search commands, move through results with arrows, and press Enter to run one.

The code uses shared demo presentation helpers. Their complete source and styling are included in the LLM build context.

Import#

TSX

import {
  Command,
  CommandDialog,
  CommandInput,
  CommandList,
  CommandEmpty,
  CommandGroup,
  CommandItem,
  CommandShortcut,
  CommandSeparator,
} from '@clidey/ux';

Inline command menu#

TSX

<Command className="rounded-lg border shadow-md w-80">
  <CommandInput placeholder="Type a command..." />
  <CommandList>
    <CommandEmpty>No results found.</CommandEmpty>
    <CommandGroup heading="Suggestions">
      <CommandItem>Calendar</CommandItem>
      <CommandItem>Search emoji</CommandItem>
      <CommandItem>Launch calculator</CommandItem>
    </CommandGroup>
    <CommandSeparator />
    <CommandGroup heading="Settings">
      <CommandItem>
        Profile
        <CommandShortcut>⌘P</CommandShortcut>
      </CommandItem>
      <CommandItem>
        Billing
        <CommandShortcut>⌘B</CommandShortcut>
      </CommandItem>
    </CommandGroup>
  </CommandList>
</Command>

Dialog (modal) command palette#

CommandDialog wraps the command inside a full-screen modal. The standard pattern is to open it with ⌘K:

TSX

import { useEffect, useState } from 'react';

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

  useEffect(() => {
    function handleKeyDown(e: KeyboardEvent) {
      if ((e.metaKey || e.ctrlKey) && e.key === 'k') {
        e.preventDefault();
        setOpen((prev) => !prev);
      }
    }
    document.addEventListener('keydown', handleKeyDown);
    return () => document.removeEventListener('keydown', handleKeyDown);
  }, []);

  return (
    <CommandDialog open={open} onOpenChange={setOpen} title="Command Palette">
      <CommandInput placeholder="Search commands, pages, settings..." />
      <CommandList>
        <CommandEmpty>No results found.</CommandEmpty>
        <CommandGroup heading="Pages">
          <CommandItem onSelect={() => { navigate('/dashboard'); setOpen(false); }}>
            Dashboard
          </CommandItem>
          <CommandItem onSelect={() => { navigate('/projects'); setOpen(false); }}>
            Projects
          </CommandItem>
          <CommandItem onSelect={() => { navigate('/settings'); setOpen(false); }}>
            Settings
          </CommandItem>
        </CommandGroup>
        <CommandSeparator />
        <CommandGroup heading="Actions">
          <CommandItem onSelect={() => { openNewProjectDialog(); setOpen(false); }}>
            <Plus className="size-4" />
            New project
            <CommandShortcut>⌘N</CommandShortcut>
          </CommandItem>
        </CommandGroup>
      </CommandList>
    </CommandDialog>
  );
}

With icons#

TSX

<CommandGroup heading="Navigation">
  <CommandItem>
    <LayoutDashboard className="size-4" />
    Dashboard
  </CommandItem>
  <CommandItem>
    <FolderOpen className="size-4" />
    Projects
  </CommandItem>
  <CommandItem>
    <Users className="size-4" />
    Team
  </CommandItem>
</CommandGroup>

Input clears on Escape#

The CommandInput automatically clears its value when Escape is pressed (before the dialog closes).

Sub-components#

ComponentDescription
CommandRoot container.
CommandDialogModal wrapper with accessible title/description.
CommandInputSearch field. Clears on Escape.
CommandListScrollable container for results.
CommandEmptyShown when no results match.
CommandGroupLabeled section with a heading.
CommandItemSelectable result item.
CommandShortcutKeyboard shortcut hint displayed on the right.
CommandSeparatorVisual divider between groups.

CommandDialog Props

PropTypeDefaultDescription
titlestring"Command Palette"Accessible dialog title (screen readers).
descriptionstring"Search for a command to run..."Accessible description.
openboolean—Controlled open state.
onOpenChange(open: boolean) => void—Called when open state changes.
showCloseButtonbooleantrueShows the close button in the top corner.

CommandItem Props

PropTypeDefaultDescription
onSelect(value: string) => void—Called when the item is selected.
disabledbooleanfalseDisables the item.
valuestring—Custom search value (defaults to text content).

Was this page helpful?