Prototyper UI

Command Palette

A command palette with search, groups, and keyboard navigation built on Base UI

Loading...

Installation

pnpm dlx shadcn@latest add https://prototyper-ui.com/r/command-palette.json
npx shadcn@latest add https://prototyper-ui.com/r/command-palette.json
yarn dlx shadcn@latest add https://prototyper-ui.com/r/command-palette.json
bunx --bun shadcn@latest add https://prototyper-ui.com/r/command-palette.json

This will add the following files to your project:

  • components/ui/command-palette.tsx

Usage

import {
  CommandPalette,
  CommandPaletteContent,
  CommandInput,
  CommandGroup,
  CommandItem,
  CommandEmpty,
  CommandList,
} from "@/components/ui/command-palette";

<CommandPalette open={open} onOpenChange={setOpen}>
  <CommandPaletteContent>
    <CommandInput />
    <CommandList>
      <CommandEmpty>No results found.</CommandEmpty>
      <CommandGroup heading="Actions">
        <CommandItem value="Search" onSelect={() => {}}>
          Search
        </CommandItem>
      </CommandGroup>
    </CommandList>
  </CommandPaletteContent>
</CommandPalette>;

Anatomy

<CommandPalette>
  <CommandPaletteContent>
    <CommandInput />
    <CommandList>
      <CommandEmpty />
      <CommandGroup>
        <CommandItem />
      </CommandGroup>
      <CommandSeparator />
    </CommandList>
  </CommandPaletteContent>
</CommandPalette>
Sub-componentdata-slotPurposeRequired
CommandPalettecommand-paletteRoot provider, manages open/close state and searchYes
CommandPaletteContentcommand-palette-contentThe popup panel with overlay backdropYes
CommandInputcommand-inputText input for filtering itemsYes
CommandListcommand-listScrollable container for groups and itemsYes
CommandGroupcommand-groupGroups related items with an optional headingNo
CommandItemcommand-itemIndividual selectable command itemYes
CommandEmptycommand-emptyShown when search yields no resultsNo
CommandSeparatorcommand-separatorVisual divider between groupsNo

Styling

Data Slots

Use data-slot attributes to target specific parts of the command palette:

Slot nameElement
command-paletteRoot provider (no DOM element)
command-palette-portalPortal wrapper
command-palette-overlayBackdrop overlay
command-palette-contentThe popup panel
command-input-wrapperWrapper around the search icon + input
command-inputThe search input element
command-listScrollable items container
command-groupGroup wrapper
command-group-headingGroup heading text
command-itemIndividual item row
command-shortcutKeyboard shortcut badge
command-emptyEmpty state message
command-separatorDivider line

Customization Examples

/* Widen the command palette */
[data-slot="command-palette-content"] {
  @apply max-w-2xl;
}

/* Custom item highlight color */
[data-slot="command-item"][data-highlighted] {
  @apply bg-primary/10;
}
{
  /* Override styles via className */
}
<CommandPaletteContent className="max-w-2xl">
  {/* ... */}
</CommandPaletteContent>;

API Reference

CommandPalette

Root component that manages dialog state, search state, and item registration.

Prop

Type

CommandPaletteContent

The popup panel rendered inside a portal with an overlay backdrop.

Prop

Type

All standard div props are forwarded via ...props.

CommandInput

Search input that filters items and handles keyboard navigation.

Prop

Type

All standard input props are forwarded via ...props.

CommandList

Scrollable container for command groups and items.

Prop

Type

All standard div props are forwarded via ...props.

CommandGroup

Groups related items under an optional heading.

Prop

Type

All standard div props are forwarded via ...props.

CommandItem

An individual selectable command.

Prop

Type

All standard div props are forwarded via ...props.

CommandEmpty

Placeholder content shown when the search query matches no items.

Prop

Type

All standard div props are forwarded via ...props.

CommandSeparator

A visual divider between groups.

Prop

Type

All standard div props are forwarded via ...props.

Accessibility

Keyboard Interactions

KeyAction
ArrowDownMoves highlight to the next enabled item
ArrowUpMoves highlight to the previous enabled item
EnterSelects the currently highlighted item
EscapeCloses the command palette
TabMoves focus to the next focusable element

ARIA Attributes

  • Each CommandItem renders with role="option" and aria-selected reflecting the highlight state.
  • aria-disabled is set on disabled items.
  • The dialog is modal -- focus is trapped inside while open.
  • The search input receives auto-focus when the palette opens.

On this page