Redpanda UI
RC
Redpanda UI

Command

Fast, composable, unstyled command menu for React.

Made by pacocoursey
Loading component...

Installation

When to use

Use this decision tree to determine when to use the Command component:

Usage

import {
  Command,
  CommandDialog,
  CommandEmpty,
  CommandGroup,
  CommandInput,
  CommandItem,
  CommandList,
  CommandSeparator,
  CommandShortcut,
  CommandSub,
  CommandSubTrigger,
  CommandSubContent,
  SimpleCommand,
} from "@/components/ui/command"
<Command>
  <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>
    <CommandSeparator />
    <CommandGroup heading="Settings">
      <CommandItem>Profile</CommandItem>
      <CommandItem>Billing</CommandItem>
      <CommandItem>Settings</CommandItem>
    </CommandGroup>
  </CommandList>
</Command>

Examples

Simple Command

A higher-level component that provides a simplified API for creating command menus.

Loading component...

SimpleCommand Props

PropTypeDefaultDescription
placeholderstring"Type a command or search..."Input placeholder text
emptyMessagestring"No results found."Message shown when no results
groupsArray<CommandGroup>-Array of command groups (required)
size'sm' | 'default' | 'lg' | 'full''default'Command size variant
classNamestring-Additional CSS classes

CommandGroup Interface

interface CommandGroup {
  heading?: string;
  items: CommandItem[];
}

interface CommandItem {
  icon?: React.ReactNode;
  label: string;
  shortcut?: string;
  disabled?: boolean;
  onSelect?: () => void;
}

Usage

import { SimpleCommand } from "@/components/ui/command"

const commandGroups = [
  {
    heading: 'Actions',
    items: [
      {
        icon: <Calendar />,
        label: 'Calendar',
        shortcut: '⌘C',
        onSelect: () => console.log('Calendar selected'),
      },
      {
        icon: <Settings />,
        label: 'Settings',
        disabled: true,
        onSelect: () => console.log('Settings selected'),
      },
    ],
  },
];

<SimpleCommand
  groups={commandGroups}
  placeholder="Search commands..."
  emptyMessage="No commands found."
/>

Dialog

Loading component...

To show the command menu in a dialog, use the <CommandDialog /> component.

export function CommandMenu() {
  const [open, setOpen] = React.useState(false)

  React.useEffect(() => {
    const down = (e: KeyboardEvent) => {
      if (e.key === "k" && (e.metaKey || e.ctrlKey)) {
        e.preventDefault()
        setOpen((open) => !open)
      }
    }
    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>
  )
}

Use CommandSub, CommandSubTrigger, and CommandSubContent to create nested command menus that open as a popover to the right of the trigger item.

Loading component...
function CommandWithSubmenu() {
  const [labelOpen, setLabelOpen] = React.useState(false)

  return (
    <Command>
      <CommandInput placeholder="Type a command or search..." />
      <CommandList>
        <CommandGroup heading="Actions">
          <CommandItem>Search</CommandItem>
          <CommandSub open={labelOpen} onOpenChange={setLabelOpen}>
            <CommandSubTrigger>Apply Label</CommandSubTrigger>
            <CommandSubContent>
              <Command>
                <CommandInput placeholder="Filter labels..." />
                <CommandList>
                  <CommandEmpty>No labels found.</CommandEmpty>
                  <CommandGroup>
                    <CommandItem>Bug</CommandItem>
                    <CommandItem>Feature</CommandItem>
                    <CommandItem>Enhancement</CommandItem>
                  </CommandGroup>
                </CommandList>
              </Command>
            </CommandSubContent>
          </CommandSub>
        </CommandGroup>
      </CommandList>
    </Command>
  )
}

CommandSub - Root wrapper that manages submenu state with a Popover.

PropTypeDescription
openbooleanWhether the submenu is open
onOpenChange(open: boolean) => voidCallback when open state changes
childrenReactNodeCommandSubTrigger and CommandSubContent

CommandSubTrigger - Item that opens the submenu when selected. Renders a chevron icon on the right.

PropTypeDefaultDescription
insetboolean?falseIndent the trigger with left padding
classNamestring?Additional CSS classes

Inherits all props from CommandItem.

CommandSubContent - Popover content for the nested command list. Opens to the right of the trigger.

PropTypeDescription
classNamestring?Additional CSS classes
childrenReactNodeNested Command with CommandList

Combobox

You can use the <Command /> component as a combobox. See the Combobox page for more information.

Props

Credits

  • We use cmdk for the command component.
  • We take our inspiration from Shadcn UI for the command style.

Built by malinskibeniamin. The source code is available on GitHub.

On this page