suiss/ui
  • Docs
  • Components
  • Patterns
  • Interactions
  • Charts
  • Blocks
  • AI
GitHubCreate
DocsComponentsPatternsInteractionsChartsBlocksAICreate
Patterns19
  • Overview
  • Action Bar
  • Action Menu
  • App Shell
  • Command Palette
  • Confirm
  • Context Actions
  • Date Picker
  • Flyout
  • Modal
  • Navbar
  • Paged List
  • Panel
  • Picker
  • Preview
  • Search Picker
  • Segment Picker
  • Split View
  • Table List
  • Trail

suiss/ui · Pattern

Command Palette

A searchable command menu that opens in a dialog on desktop and a drawer on mobile.

Command Palette is an open-source pattern from suiss/ui for React. The @esuiss/ui CLI copies its source into your project, so you own the code.

import {
  CalculatorIcon,
  CalendarBlankIcon,
  CreditCardIcon,
  GearIcon,
  SmileyIcon,
  UserIcon,
} from "@phosphor-icons/react"
import {
  CommandPalette,
  CommandPaletteContent,
  CommandPaletteTrigger,
} from "@/components/patterns/command-palette"
import { Button } from "@/components/ui/button"
import {
  CommandEmpty,

CommandPalette hosts a Command list inside a Dialog on desktop, positioned in the upper third of the viewport, and inside a bottom Drawer with a swipe handle below the 48rem breakpoint. A global keyboard shortcut toggles it: Cmd+K on macOS and Ctrl+K elsewhere by default.

Use it for app-wide search and quick actions.

Installation

$ pnpm dlx shadcn@latest add @esuiss/command-palette

Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:

$ pnpm dlx @esuiss/ui@latest add patterns command-palette
  1. Add the cn helper.

  2. Add the pieces it builds on: Command, Dialog, Drawer, use-mobile, use-platform.

  3. Copy and paste the following code into your project.

components/patterns/command-palette.tsx
"use client"

import * as React from "react"
import { Command } from "@/components/ui/command"
import {
  Dialog,
  DialogContent,
  DialogDescription,
  DialogHeader,
  DialogTitle,
  DialogTrigger,
} from "@/components/ui/dialog"
import {
  Drawer,
  DrawerContent,
  DrawerDescription,
  1. Update the import paths to match your project setup.

Usage

import { CommandPalette, CommandPaletteTrigger, CommandPaletteContent } from "@/components/patterns/command-palette"
import { Button } from "@/components/ui/button"
import {
  CommandEmpty,
  CommandGroup,
  CommandInput,
  CommandItem,
  CommandList,
  CommandShortcut,
} from "@/components/ui/command"
<div className="flex min-h-svh items-center justify-center">
  <CommandPalette>
    <CommandPaletteTrigger render={<Button variant="outline" />}>
      Search
    </CommandPaletteTrigger>
    <CommandPaletteContent>
      <CommandInput placeholder="Type a command or search..." />
      <CommandList>
        <CommandEmpty>No results found.</CommandEmpty>
        <CommandGroup heading="Settings">
          <CommandItem>
            Profile
            <CommandShortcut mod>P</CommandShortcut>
          </CommandItem>
          <CommandItem>
            Billing
            <CommandShortcut mod>B</CommandShortcut>
          </CommandItem>
        </CommandGroup>
      </CommandList>
    </CommandPaletteContent>
  </CommandPalette>
</div>
<div className="flex min-h-svh items-center justify-center">
  <CommandPalette>
    <CommandPaletteTrigger asChild>
      <Button variant="outline">Search</Button>
    </CommandPaletteTrigger>
    <CommandPaletteContent>
      <CommandInput placeholder="Type a command or search..." />
      <CommandList>
        <CommandEmpty>No results found.</CommandEmpty>
        <CommandGroup heading="Settings">
          <CommandItem>
            Profile
            <CommandShortcut mod>P</CommandShortcut>
          </CommandItem>
          <CommandItem>
            Billing
            <CommandShortcut mod>B</CommandShortcut>
          </CommandItem>
        </CommandGroup>
      </CommandList>
    </CommandPaletteContent>
  </CommandPalette>
</div>

Composition

Use the following composition to build a CommandPalette:

CommandPalette
├── CommandPaletteTrigger
└── CommandPaletteContent

Examples

With close button

Set showCloseButton to show an icon close button in the corner of the popup. On mobile the input gains end padding so it does not run under the button.

import {
  CalculatorIcon,
  CalendarBlankIcon,
  CreditCardIcon,
  GearIcon,
  SmileyIcon,
  UserIcon,
} from "@phosphor-icons/react"
import {
  CommandPalette,
  CommandPaletteContent,
  CommandPaletteTrigger,
} from "@/components/patterns/command-palette"
import { Button } from "@/components/ui/button"
import {
  CommandEmpty,

With close label

Set closeLabel together with showCloseButton to replace the close icon with text, here Cancel.

import {
  CalculatorIcon,
  CalendarBlankIcon,
  CreditCardIcon,
  GearIcon,
  SmileyIcon,
  UserIcon,
} from "@phosphor-icons/react"
import {
  CommandPalette,
  CommandPaletteContent,
  CommandPaletteTrigger,
} from "@/components/patterns/command-palette"
import { Button } from "@/components/ui/button"
import {
  CommandEmpty,

Floating

Set floating to inset the mobile drawer from the screen edges with fully rounded corners.

import {
  CalculatorIcon,
  CalendarBlankIcon,
  CreditCardIcon,
  GearIcon,
  SmileyIcon,
  UserIcon,
} from "@phosphor-icons/react"
import {
  CommandPalette,
  CommandPaletteContent,
  CommandPaletteTrigger,
} from "@/components/patterns/command-palette"
import { Button } from "@/components/ui/button"
import {
  CommandEmpty,

Accessibility

  • The popup is a dialog named by title and described by description.
  • Opening the palette focuses the search input, and the first enabled option is selected.
  • Arrow keys move between options and skip disabled ones; typing filters the list.
  • Escape closes the palette and returns focus to the trigger.

API Reference

CommandPalette

The root that renders a Dialog on desktop and a Drawer on mobile and registers the hotkey.

PropTypeDefault
openboolean-
defaultOpenbooleanfalse
onOpenChange(open: boolean) => void-
hotkeystring | false"k"
floatingboolean-
childrenReact.ReactNode-

The palette can be controlled with open and onOpenChange or uncontrolled with defaultOpen; the hotkey and the trigger update the same state, and onOpenChange also fires for the hotkey. hotkey is the letter that toggles the palette together with Cmd on macOS or Ctrl elsewhere. Set it to another letter to change the shortcut, or to false to disable it.

CommandPaletteTrigger

The button that opens the palette.

PropTypeDefault
renderReact.ReactElement-
PropTypeDefault
asChildbooleanfalse

Also accepts the props of DialogTrigger.

Also accepts className, children, id and aria-label.

Use render to replace the default button with your own element, for example a Button with a Kbd hint.

Set asChild to render your own button in place of the default one, for example a Button with a Kbd hint.

CommandPaletteContent

The popup that wraps a Command with a visually hidden title and description.

PropTypeDefault
titlestring"Command Palette"
descriptionstring"Search for a command to run..."
showCloseButtonbooleanfalse
closeLabelstring-

Also accepts the props of React.ComponentProps<typeof Command>.

Fill it with CommandInput, CommandList, CommandGroup, CommandItem and the other Command parts. title and description name and describe the dialog and are rendered visually hidden. Remaining props, including className, pass through to the inner Command, not the dialog or drawer. On mobile the list is capped at 60dvh.

Each part sets a data-slot, such as command-palette or command-palette-content, for styling.

NextConfirmPreviousApp Shell

On this page

  1. 01Installation
  2. 02Usage
  3. 03Composition
  4. 04Examples
    • With close button
    • With close label
    • Floating
  5. 05Accessibility
  6. 06API Reference
    • CommandPalette
    • CommandPaletteTrigger
    • CommandPaletteContent