suiss/ui
  • Docs
  • Components
  • Patterns
  • Interactions
  • Charts
  • Blocks
  • AI
GitHubCreate
DocsComponentsPatternsInteractionsChartsBlocksAICreate
Components84
  • Overview
  • Accordion
  • Alert
  • Alert Dialog
  • Alert Sheet
  • Amount Input
  • Aspect Ratio
  • Attachment
  • Avatar
  • Badge
  • Bottom Bar
  • Breadcrumb
  • Bubble
  • Button
  • Button Group
  • Calendar
  • Card
  • Carousel
  • Chart
  • Checkbox
  • Chip
  • Code Block
  • Collapsible
  • Combobox
  • Command
  • Context Menu
  • Dialog
  • Direction
  • Drawer
  • Dropdown Menu
  • Empty
  • FAB
  • Field
  • Fullscreen Menu
  • Haptics
  • Header
  • Hover Card
  • Icon
  • Input
  • Input Accessory Bar
  • Input Group
  • Input OTP
  • Item
  • Kbd
  • Keyboard Scroll View
  • Keypad
  • Label
  • Marker
  • Menubar
  • Message
  • Message Scroller
  • Native Select
  • Navigation Menu
  • Page Indicator
  • Pagination
  • Pin Pad
  • Popover
  • Progress
  • QR Scanner
  • Questionnaire
  • Radio Group
  • Resizable
  • Screen
  • Scroll Area
  • Select
  • Separator
  • Sheet
  • Sidebar
  • Signature Pad
  • Skeleton
  • Slider
  • Spinner
  • Switch
  • Tab Bar
  • Table
  • Tabs
  • Text
  • Textarea
  • Toast
  • Toggle
  • Toggle Group
  • Tooltip
  • Trace
  • Wheel Picker
  • Widget

suiss/ui · Component

Command

A searchable menu of commands, used inline or as a command palette in a dialog.

Command is an open-source component 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 {
  Command,
  CommandEmpty,
  CommandGroup,
  CommandInput,
  CommandItem,
  CommandList,
  CommandSeparator,

Command is built on cmdk. The Command root filters and orders its items as people type into CommandInput. CommandList holds the results: CommandGroup sections with a heading, CommandItem rows, CommandSeparator dividers, and a CommandEmpty message shown when nothing matches. CommandShortcut displays a keyboard shortcut at the end of an item.

CommandDialog places a Command in a modal dialog for a command palette. Use a command menu for actions and navigation that people search by name. To pick a value for a form field, use a combobox instead.

Installation

$ pnpm dlx shadcn@latest add @esuiss/command

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 command
  1. Install the following dependencies and add the cn helper:
$ pnpm add @phosphor-icons/react cmdk
  1. Add the pieces it builds on: Dialog, use-platform.

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

components/ui/command.tsx
"use client"

import { CheckIcon, MagnifyingGlassIcon } from "@phosphor-icons/react"
import { Command as CommandPrimitive, useCommandState } from "cmdk"
import type * as React from "react"
import {
  Dialog,
  DialogContent,
  DialogDescription,
  DialogHeader,
  DialogTitle,
} from "@/components/ui/dialog"
import { useModifierKey } from "@/hooks/use-platform"
import { cn } from "@/lib/utils"

function Command({
  1. Update the import paths to match your project setup.

Usage

import {
  Command,
  CommandDialog,
  CommandEmpty,
  CommandGroup,
  CommandInput,
  CommandItem,
  CommandList,
  CommandSeparator,
  CommandShortcut,
} from "@/components/ui/command"
<div className="w-140">
  <Command className="ring-foreground/5 shadow-md ring-1">
    <CommandInput placeholder="Type a command or search..." />
    <CommandList>
      <CommandEmpty>No results found.</CommandEmpty>
      <CommandGroup heading="Suggestions">
        <CommandItem>
          <CalendarBlankIcon />
          Calendar
        </CommandItem>
        <CommandItem disabled>
          <CalculatorIcon />
          Calculator
        </CommandItem>
      </CommandGroup>
      <CommandSeparator />
      <CommandGroup heading="Settings">
        <CommandItem>
          <UserIcon />
          Profile
          <CommandShortcut mod>P</CommandShortcut>
        </CommandItem>
      </CommandGroup>
    </CommandList>
  </Command>
</div>

Composition

Use the following composition to build a CommandDialog:

CommandDialog
└── Command
    ├── CommandInput
    └── CommandList
        ├── CommandEmpty
        ├── CommandGroup
        │   └── CommandItem
        │       └── CommandShortcut
        └── CommandSeparator

Examples

Empty

A command menu with no items. CommandEmpty shows its message because nothing matches.

import {
  Command,
  CommandEmpty,
  CommandInput,
  CommandList,
} from "@/components/ui/command"

export default function CommandEmptyExample() {
  return (
    <Command className="w-140 ring-foreground/5 shadow-md ring-1">
      <CommandInput placeholder="Search projects..." />
      <CommandList>
        <CommandEmpty>No projects found.</CommandEmpty>
      </CommandList>
    </Command>
  )

Dialog

Wrap the Command in CommandDialog for a command palette opened from a button. It closes with Escape and returns focus to the button.

import {
  CalculatorIcon,
  CalendarBlankIcon,
  CreditCardIcon,
  GearIcon,
  SmileyIcon,
  UserIcon,
} from "@phosphor-icons/react"
import * as React from "react"
import { Button } from "@/components/ui/button"
import {
  Command,
  CommandDialog,
  CommandEmpty,
  CommandGroup,
  CommandInput,

Dialog open

A command palette that is open when the page loads.

import {
  CalculatorIcon,
  CalendarBlankIcon,
  CreditCardIcon,
  GearIcon,
  SmileyIcon,
  UserIcon,
} from "@phosphor-icons/react"
import * as React from "react"
import { Button } from "@/components/ui/button"
import {
  Command,
  CommandDialog,
  CommandEmpty,
  CommandGroup,
  CommandInput,

Accessibility

  • The input has the combobox role and items have the option role. The highlighted item sets aria-selected and disabled items set aria-disabled.
  • The first item is highlighted by default. Arrow keys move the highlight and skip disabled items; Enter selects the highlighted item.
  • CommandDialog renders a dialog named by its title, moves focus inside when it opens, closes with Escape, and returns focus to the element that opened it.
  • CommandShortcut is hidden on small screens.

API Reference

Command

The root that filters and manages the items.

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

Compose CommandInput and CommandList inside Command, and put groups and items in the list. Inside a dialog, Command drops its own background and rounded corners.

CommandDialog

A modal dialog that presents a command menu as a palette.

PropTypeDefault
titlestring"Command Palette"
descriptionstring"Search for a command to run..."
classNamestring-
showCloseButtonbooleanfalse
childrenReact.ReactNodeRequired

Also accepts the props of Dialog.

Control the palette with open and onOpenChange.

Control the palette with isOpen and onOpenChange.

title and description name and describe the dialog for assistive technology and are visually hidden. className applies to the dialog's content panel. Pass a Command as the children. The palette uses a translucent, blurred popover background.

CommandInput

The search field, shown with a magnifying glass icon.

Also accepts the props of React.ComponentProps<typeof CommandPrimitive.Input>.

CommandList

The scrollable container for results.

Also accepts the props of React.ComponentProps<typeof CommandPrimitive.List>.

CommandEmpty

Content shown when no items match the search.

Also accepts the props of React.ComponentProps<typeof CommandPrimitive.Empty>.

CommandGroup

A section of related items with an optional heading.

Also accepts the props of React.ComponentProps<typeof CommandPrimitive.Group>.

CommandSeparator

A divider between groups.

Also accepts the props of React.ComponentProps<typeof CommandPrimitive.Separator>.

CommandItem

A selectable command.

Also accepts the props of React.ComponentProps<typeof CommandPrimitive.Item>.

Respond to a chosen item with its onSelect callback, and set disabled on items that are unavailable. The highlighted item gets data-selected and is filled with the primary color, and disabled items get data-disabled="true". An item with data-checked="true" shows a check mark, unless it contains a CommandShortcut.

CommandShortcut

Displays a keyboard shortcut at the end of an item.

PropTypeDefault
modboolean-

Also accepts the props of React.ComponentProps<"span">.

Set mod to prefix the shortcut with the platform modifier key: ⌘ on Apple platforms and Ctrl+ elsewhere.

Each part sets a data-slot, such as command-item or command-input-wrapper, for styling.

NextContext MenuPreviousCombobox

On this page

  1. 01Installation
  2. 02Usage
  3. 03Composition
  4. 04Examples
    • Empty
    • Dialog
    • Dialog open
  5. 05Accessibility
  6. 06API Reference
    • Command
    • CommandDialog
    • CommandInput
    • CommandList
    • CommandEmpty
    • CommandGroup
    • CommandSeparator
    • CommandItem
    • CommandShortcut