Skip to content
All components
Overlays

Command

Let people type to find and run a command or jump to a place, from a filtered list that stays operable entirely from the keyboard.

A command palette built on cmdk.

Installation

tdpxl is not an npm dependency of your app. The @tdpxl/cli command (not published to npm yet) copies the source into your project, with the registry items and npm packages it imports.

npx @tdpxl/cli add command

Then import it from @/components/ui/command. New project? Start with the installation guide.

Examples

Each example is one branch of the official demo, rendered in its own frame. The code is that branch as you would write it, with imports pointing at the default install paths.

Palette

Open a command palette from a button or Ctrl/Cmd+K. The dialog is named by its title, runs the chosen command, closes and returns focus to the opener.

"use client"

import {
  FolderPlusIcon,
  LayoutDashboardIcon,
  SearchIcon,
  SettingsIcon,
  UserPlusIcon,
} from "lucide-react"
import * as React from "react"

import { Button } from "@/components/ui/button"
import {
  Command,
  CommandDialog,
  CommandEmpty,
  CommandGroup,
  CommandInput,
  CommandItem,
  CommandList,
  CommandSeparator,
  CommandShortcut,
} from "@/components/ui/command"
import { Kbd, KbdGroup } from "@/components/ui/kbd"

/** Opens a controlled dialog and returns focus to whatever opened it. */
function useRestoringOpen() {
  const [open, setOpen] = React.useState(false)
  const isOpen = React.useRef(false)
  const returnFocus = React.useRef<HTMLElement | null>(null)
  const change = React.useCallback((next: boolean) => {
    if (next === isOpen.current) return
    isOpen.current = next
    if (next) returnFocus.current = document.activeElement as HTMLElement | null
    setOpen(next)
    if (!next) requestAnimationFrame(() => returnFocus.current?.focus())
  }, [])
  return [open, change] as const
}

export function CommandPalette() {
  const [paletteOpen, setPaletteOpen] = useRestoringOpen()
  const [lastAction, setLastAction] = React.useState<string | null>(null)
  
  

  React.useEffect(() => {
    function onKeyDown(event: KeyboardEvent) {
      if (event.key.toLowerCase() === "k" && (event.metaKey || event.ctrlKey) && !event.repeat) {
        event.preventDefault()
        setPaletteOpen(true)
      }
    }
    document.addEventListener("keydown", onKeyDown)
    return () => document.removeEventListener("keydown", onKeyDown)
  }, [setPaletteOpen])

  function run(action: string) {
    setLastAction(action)
    setPaletteOpen(false)
  }

  return (
    <div className="flex w-full flex-col items-start gap-6">
      <div className="flex flex-col items-start gap-2">
        <Button
          intent="neutral"
          emphasis="stroke"
          aria-keyshortcuts="Control+K Meta+K"
          onClick={() => setPaletteOpen(true)}
        >
          <SearchIcon />
          Search commands
          <KbdGroup aria-hidden="true">
            <Kbd>Ctrl</Kbd>
            <Kbd>K</Kbd>
          </KbdGroup>
        </Button>
        <p className="text-paragraph-sm text-sub-600" aria-live="polite">
          {lastAction ? `Last command: ${lastAction}` : "No command run yet."}
        </p>
        <CommandDialog
          open={paletteOpen}
          onOpenChange={setPaletteOpen}
          title="Command palette"
          description="Search for a page or an action, then press Enter to run it."
        >
          <CommandInput placeholder="Search pages and actions..." />
          <CommandList>
            <CommandEmpty>Nothing matches that search. Try a page name or a verb.</CommandEmpty>
            <CommandGroup heading="Go to">
              <CommandItem onSelect={() => run("Open dashboard")}>
                <LayoutDashboardIcon />
                Dashboard
                <CommandShortcut>G D</CommandShortcut>
              </CommandItem>
              <CommandItem onSelect={() => run("Open account settings")}>
                <SettingsIcon />
                Account settings
                <CommandShortcut>G S</CommandShortcut>
              </CommandItem>
            </CommandGroup>
            <CommandSeparator />
            <CommandGroup heading="Actions">
              <CommandItem onSelect={() => run("Create project")}>
                <FolderPlusIcon />
                Create project
                <CommandShortcut>Ctrl Alt N</CommandShortcut>
              </CommandItem>
              <CommandItem onSelect={() => run("Invite teammate")}>
                <UserPlusIcon />
                Invite teammate
              </CommandItem>
            </CommandGroup>
          </CommandList>
        </CommandDialog>
      </div>
    </div>
  )
}

Status picker

Pick one value from a filtered list inside a command dialog. Keywords let synonyms match, the disabled option cannot be chosen, and focus returns to the trigger.

"use client"

import * as React from "react"

import { Button } from "@/components/ui/button"
import {
  CommandDialog,
  CommandEmpty,
  CommandGroup,
  CommandInput,
  CommandItem,
  CommandList,
} from "@/components/ui/command"

const statuses = [
  { value: "backlog", label: "Backlog", keywords: ["later", "icebox"] },
  { value: "in-progress", label: "In progress", keywords: ["doing", "started"] },
  { value: "in-review", label: "In review", keywords: ["pr", "approval"] },
  { value: "done", label: "Done", keywords: ["complete", "closed"] },
]

/** Opens a controlled dialog and returns focus to whatever opened it. */
function useRestoringOpen() {
  const [open, setOpen] = React.useState(false)
  const isOpen = React.useRef(false)
  const returnFocus = React.useRef<HTMLElement | null>(null)
  const change = React.useCallback((next: boolean) => {
    if (next === isOpen.current) return
    isOpen.current = next
    if (next) returnFocus.current = document.activeElement as HTMLElement | null
    setOpen(next)
    if (!next) requestAnimationFrame(() => returnFocus.current?.focus())
  }, [])
  return [open, change] as const
}

export function CommandStatusPicker() {
  const [paletteOpen, setPaletteOpen] = useRestoringOpen()
  const [lastAction, setLastAction] = React.useState<string | null>(null)
  const [statusOpen, setStatusOpen] = useRestoringOpen()
  const [status, setStatus] = React.useState("in-progress")

  React.useEffect(() => {
    function onKeyDown(event: KeyboardEvent) {
      if (event.key.toLowerCase() === "k" && (event.metaKey || event.ctrlKey) && !event.repeat) {
        event.preventDefault()
        setPaletteOpen(true)
      }
    }
    document.addEventListener("keydown", onKeyDown)
    return () => document.removeEventListener("keydown", onKeyDown)
  }, [setPaletteOpen])

  function run(action: string) {
    setLastAction(action)
    setPaletteOpen(false)
  }

  return (
    <div className="flex w-full flex-col items-start gap-6">
      <div className="flex flex-col items-start gap-2">
        <Button intent="neutral" emphasis="stroke" onClick={() => setStatusOpen(true)}>
          Change status
        </Button>
        <p className="text-paragraph-sm text-sub-600" aria-live="polite">
          Status: {statuses.find((item) => item.value === status)?.label}
        </p>
        <CommandDialog
          open={statusOpen}
          onOpenChange={setStatusOpen}
          title="Change issue status"
          description="Type to filter statuses. Synonyms such as doing or closed also match."
        >
          <CommandInput placeholder="Filter statuses..." />
          <CommandList>
            <CommandEmpty>No status matches that search.</CommandEmpty>
            <CommandGroup heading="Statuses">
              {statuses.map((item) => (
                <CommandItem
                  key={item.value}
                  value={item.value}
                  keywords={[item.label, ...item.keywords]}
                  onSelect={(value) => {
                    setStatus(value)
                    setStatusOpen(false)
                  }}
                >
                  {item.label}
                  {item.value === status ? <span className="ms-auto text-label-xs text-sub-600">Current</span> : null}
                </CommandItem>
              ))}
              <CommandItem value="archived" disabled>
                Archived (requires owner access)
              </CommandItem>
            </CommandGroup>
          </CommandList>
        </CommandDialog>
      </div>
    </div>
  )
}

API reference

Generated from the component's TypeScript signatures. Inherited DOM and primitive props are listed separately.

Command

Search and activate commands or compose command-style option lists.

Command props
PropTypeDefaultDescription
childrenReact.ReactNode—Represents all of the things React can render.
defaultValuestring | (readonly string[] & string) | undefined—Optional default item value when it is initially rendered.
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
labelstring | undefined—Accessible label for this command menu. Not shown visibly.
shouldFilterboolean | undefined—Optionally set to false to turn off the automatic filtering and sorting. If false, you must conditionally render valid items based on the search query yourself.
filter((value: string, search: string, keywords?: string[]) => number) | undefined—Custom filter function for whether each command menu item should matches the given search query. It should return a number between 0 and 1, with 1 being the best match and 0 being hidden entirely. By default, uses the command-score library.
valuestring | undefined—Optional controlled state of the selected command menu item.
onValueChange((value: string) => void) | undefined—Event handler called when the selected item of the menu changes.
loopboolean | undefined—Optionally set to true to turn on looping around when using the arrow keys.
disablePointerSelectionboolean | undefined—Optionally set to true to disable selection via pointer events.
vimBindingsboolean | undefined—Set to false to disable ctrl+n/j/p/k shortcuts. Defaults to true.
Inherited props (13)
Command inherited props
PropTypeDefaultDescription
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLDivElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLDivElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLDivElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLDivElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.
asChildboolean | undefined—Merge this part into one child instead of its default element. Preserve that child's semantics, ref support and accessibility attributes.
refReact.Ref<HTMLDivElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).

CommandDialog

The CommandDialog part of command. Use it with the complete source composition and preserve its required parent context.

CommandDialog props
PropTypeDefaultDescription
childrenReact.ReactNode—Represents all of the things React can render.
titlestring | undefined"Command palette"Accessible dialog title rendered through DialogTitle. Describe the operation opened by the trigger.
descriptionstring | undefined"Search for a command to run."Accessible dialog description explaining the available interaction, without replacing its title.
Inherited props (4)
CommandDialog inherited props
PropTypeDefaultDescription
openboolean | undefined—Controlled visibility state. Pair with onOpenChange so requested state changes can be applied.
defaultOpenboolean | undefined—Initial uncontrolled visibility state. Later changes use the primitive's controls or controlled open API.
onOpenChange((open: boolean) => void) | undefined—Receive the requested open state. Apply it to open when controlled.
modalboolean | undefined—Whether this overlay uses modal behavior. Preserve the corresponding background interaction and focus behavior.

CommandEmpty

The CommandEmpty part of command. Use it with the complete source composition and preserve its required parent context.

CommandEmpty props
PropTypeDefaultDescription
childrenReact.ReactNode—Represents all of the things React can render.
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
Inherited props (14)
CommandEmpty inherited props
PropTypeDefaultDescription
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLDivElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLDivElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLDivElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLDivElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.
asChildboolean | undefined—Merge this part into one child instead of its default element. Preserve that child's semantics, ref support and accessibility attributes.
refReact.Ref<HTMLDivElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).

CommandGroup

Group related parts while preserving the parent component's required composition.

CommandGroup props
PropTypeDefaultDescription
childrenReact.ReactNode—Represents all of the things React can render.
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
headingReact.ReactNode—Optional heading to render for this group.
valuestring | undefined—If no heading is provided, you must provide a value that is unique for this group.
forceMountboolean | undefined—Whether this group is forcibly rendered regardless of filtering.
Inherited props (14)
CommandGroup inherited props
PropTypeDefaultDescription
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLDivElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLDivElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLDivElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLDivElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.
asChildboolean | undefined—Merge this part into one child instead of its default element. Preserve that child's semantics, ref support and accessibility attributes.
refReact.Ref<HTMLDivElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).

CommandInput

The CommandInput part of command. Use it with the complete source composition and preserve its required parent context.

CommandInput props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
valuestring | undefined—Optional controlled state for the value of the search input.
onValueChange((search: string) => void) | undefined—Event handler called when the search value changes.
Inherited props (30)
CommandInput inherited props
PropTypeDefaultDescription
formstring | undefined—ID of the form associated with this control, including when it is rendered outside that form element.
patternstring | undefined—Native input validation pattern. Provide readable format guidance and associated validation feedback.
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLInputElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLInputElement> | undefined—Receive the native blur event when focus leaves this control.
onKeyDownReact.KeyboardEventHandler<HTMLInputElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLInputElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLInputElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.
asChildboolean | undefined—Merge this part into one child instead of its default element. Preserve that child's semantics, ref support and accessibility attributes.
altstring | undefined—Text alternative for the image. Identify informative images; use an empty alternative only when the image is genuinely decorative.
srcstring | undefined—Image source URL. Supply alternative text appropriate to whether the image conveys identity or is decorative.
disabledboolean | undefined—Make the supported control unavailable through its native or primitive disabled semantics. This does not disable arbitrary child links.
namestring | undefined—Name used by the control's form submission or primitive form integration.
multipleboolean | undefined—Allow multiple values where the native element or primitive supports them, using its source-defined value shape.
checkedboolean | undefined—Current checked state. Apply the requested value from onCheckedChange when the parent owns this state.
autoCompleteReact.HTMLInputAutoCompleteAttribute | undefined—Native autocomplete hint appropriate to the field's actual purpose.
maxstring | number | undefined—Maximum supported numeric value.
maxLengthnumber | undefined—Maximum allowed text length for native input or code entry.
minstring | number | undefined—Minimum supported numeric value.
minLengthnumber | undefined—Minimum allowed text length for native validation.
placeholderstring | undefined—Prompt shown before a value is selected or entered. Supply an accessible label separately.
readOnlyboolean | undefined—Prevent value editing while preserving readable content. Read-only behavior differs from disabled behavior.
requiredboolean | undefined—Mark this control as required using its native or primitive semantics. Consumers own contextual validation feedback.
stepstring | number | undefined—Numeric increment used for slider or native input changes.
refReact.Ref<HTMLInputElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).

CommandItem

One item within its parent composition. Keep parent context and the value, label or state required by the source API.

CommandItem props
PropTypeDefaultDescription
childrenReact.ReactNode—Represents all of the things React can render.
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
disabledboolean | undefined—Whether this item is currently disabled.
onSelect((value: string) => void) | undefined—Event handler for when this item is selected, either via click or keyboard selection.
valuestring | undefined—A unique value for this item. If no value is provided, it will be inferred from children or the rendered textContent. If your textContent changes between renders, you _must_ provide a stable, unique value.
keywordsstring[] | undefined—Optional keywords to match against when filtering.
forceMountboolean | undefined—Whether this item is forcibly rendered regardless of filtering.
Inherited props (13)
CommandItem inherited props
PropTypeDefaultDescription
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLDivElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLDivElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLDivElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
asChildboolean | undefined—Merge this part into one child instead of its default element. Preserve that child's semantics, ref support and accessibility attributes.
refReact.Ref<HTMLDivElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).

CommandList

The CommandList part of command. Use it with the complete source composition and preserve its required parent context.

CommandList props
PropTypeDefaultDescription
childrenReact.ReactNode—Represents all of the things React can render.
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
labelstring | undefined—Accessible label for this List of suggestions. Not shown visibly.
Inherited props (14)
CommandList inherited props
PropTypeDefaultDescription
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLDivElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLDivElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLDivElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLDivElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.
asChildboolean | undefined—Merge this part into one child instead of its default element. Preserve that child's semantics, ref support and accessibility attributes.
refReact.Ref<HTMLDivElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).

CommandSeparator

Visual or semantic separation between adjacent items. It is not an operable item.

CommandSeparator props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
alwaysRenderboolean | undefined—Whether this separator should always be rendered. Useful if you disable automatic filtering.
Inherited props (14)
CommandSeparator inherited props
PropTypeDefaultDescription
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLDivElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLDivElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLDivElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLDivElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.
asChildboolean | undefined—Merge this part into one child instead of its default element. Preserve that child's semantics, ref support and accessibility attributes.
refReact.Ref<HTMLDivElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).

CommandShortcut

The CommandShortcut part of command. Use it with the complete source composition and preserve its required parent context.

CommandShortcut props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
Inherited props (13)
CommandShortcut inherited props
PropTypeDefaultDescription
refReact.Ref<HTMLSpanElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLSpanElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLSpanElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLSpanElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLSpanElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLSpanElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLSpanElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.

Accessibility & usage

From registry/ui/command.meta.json (authored guidance; human review may still be pending). Behavior is checked by Storybook tests, not certified here.

When to use

  • A command palette over the whole app: CommandDialog opened from a visible button and, optionally, a Ctrl/Cmd+K shortcut that the application registers.
  • Too many actions or destinations to browse in a menu, where typing a few letters is faster than scanning.
  • The searchable list inside a picker you compose yourself (for example inside a popover), when a form field is not needed.
  • Grouping results (CommandGroup with heading) and showing shortcut hints (CommandShortcut) for frequent commands.

When not to use

  • Choosing a value for a form field; use the combobox, which brings the field label, popover and selected value.
  • A short list of actions (fewer than about seven) for one object; a dropdown menu is faster to scan than to search.
  • The only way to reach important features; palettes are an accelerator for experienced users, so keep visible navigation and buttons.
  • Server-side search over large data sets by itself: cmdk filters the items that are rendered; remote results, debouncing and loading are the consumer's job.

Anatomy

Command
cmdk root. Owns filtering and the active item; accepts cmdk props such as label, value/onValueChange, shouldFilter, filter and loop.
CommandDialog
Modal wrapper built on Dialog. title and description (with defaults) render a visually hidden DialogTitle/DialogDescription, and title also labels the inner Command. Accepts Dialog root props (open, onOpenChange, defaultOpen); it has no close button.
CommandInput
Search field with role combobox. Keeps real DOM focus while aria-activedescendant points at the active option; placeholder and controlled value/onValueChange come from cmdk.
CommandList
Scrollable listbox of results, bounded in height.
CommandEmpty
Shown only when nothing matches. Exposed as a disabled option so it is announced but cannot be activated.
CommandGroup
Groups items under an optional heading that is announced with them.
CommandItem
One option (role option). Supports value, keywords, disabled and onSelect(value).
CommandSeparator
Decorative divider between groups, hidden from assistive technology.
CommandShortcut
Plain text span at the end of an item for a shortcut hint. Displays keys only.

Keyboard & interaction

  • Follows the WAI-ARIA APG combobox-with-listbox model: focus stays in the input while Arrow Up/Down move the active option, Home/End jump to the ends, and Enter runs the active item's onSelect.
  • Typing filters items by value and keywords and re-ranks them; groups with no matches hide, and the first match becomes active.
  • Disabled items are skipped by the arrow keys and cannot be selected; the empty state cannot be activated either.
  • In CommandDialog, focus moves into the search input on open and stays inside the dialog (WCAG 2.1.2 is satisfied by Escape); Escape or an outside click closes it.
  • A DialogTrigger is not composed by CommandDialog, so when you open it from your own button or a global shortcut, record the opener and return focus to it on close (WCAG 2.4.3).
  • Closing the dialog does not clear selection state you own; decide whether the search text resets between openings.

Responsive behavior

  • The dialog is centered and narrows with the viewport; at 320px the input and results must remain fully visible without horizontal scrolling (WCAG 1.4.10).
  • The list scrolls inside a bounded height so the input stays visible; keep the active option scrolled into view and not hidden behind sticky headers (WCAG 2.4.11).
  • On touch screens, open the palette from a visible button; a keyboard shortcut alone is unreachable without a hardware keyboard.
  • Shortcut hints are noise on touch-only devices; consider hiding CommandShortcut there while keeping the command itself.
  • Keep option rows at least 24 CSS pixels tall (WCAG 2.5.8); larger rows help on touch.

Content guidelines

  • Give CommandDialog a title that names the job ('Command palette', 'Change issue status') and a description that says how to use it.
  • Write the placeholder as a prompt of what can be found ('Search pages and actions...'), not as the only label.
  • Start action items with a verb ('Create project', 'Invite teammate'); name destinations with the page name ('Account settings').
  • Write a helpful empty state that suggests what to try next instead of only 'No results'.
  • Add keywords for synonyms and common misspellings so people find commands in their own words.
  • Keep group headings short nouns ('Go to', 'Actions') and avoid repeating them inside item labels.

Alternatives

  • Combobox — A labelled form field that selects one searchable value.
  • Dropdown menu — A small action list without search behind one trigger.
  • Menubar — Persistent, browsable command groups in a desktop-style editor.
  • Dialog — A task that needs a form or explanation rather than a list to pick from.

Resources