{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "search-command",
  "title": "Search Command",
  "description": "Search pages and run actions from a polished, keyboard-first command menu.",
  "dependencies": [
    "lucide-react",
    "react-hotkeys-hook"
  ],
  "registryDependencies": [
    "button",
    "command",
    "kbd"
  ],
  "files": [
    {
      "path": "src/registry/components/search-command/search-command.tsx",
      "content": "\"use client\";\n\nimport { CopyIcon, CornerDownLeftIcon, SearchIcon } from \"lucide-react\";\nimport * as React from \"react\";\nimport { useHotkeys } from \"react-hotkeys-hook\";\n\nimport { Button } from \"@/components/ui/button\";\nimport {\n\tCommandDialog,\n\tCommandEmpty,\n\tCommandGroup,\n\tCommandInput,\n\tCommandItem,\n\tCommandList,\n\tCommandShortcut,\n} from \"@/components/ui/command\";\nimport { Kbd, KbdGroup } from \"@/components/ui/kbd\";\nimport { cn } from \"@/lib/utils\";\n\nexport type SearchCommandItem = {\n\t/** Stable identity when items may be reordered. */\n\tid?: string;\n\t/** Primary searchable label. */\n\ttitle: string;\n\t/** Optional text included in search without being displayed. */\n\tdescription?: string;\n\t/** Overrides the value used by the command menu's filter. */\n\tvalue?: string;\n\t/** Additional terms that should match this item. */\n\tkeywords?: readonly string[];\n\ticon?: React.ReactNode;\n\t/** Supporting metadata displayed at the end of the row. */\n\tmeta?: React.ReactNode;\n\t/** Compact keyboard sequence displayed at the end of the row. */\n\tshortcut?: string;\n\t/** Overrides the footer action while this item is highlighted. */\n\tactionLabel?: string;\n\tdisabled?: boolean;\n\t/** Runs immediately before the menu closes. */\n\tonBeforeSelect?: () => void;\n\tonSelect?: () => void;\n};\n\nexport type SearchCommandGroup = {\n\theading: string;\n\titems: readonly SearchCommandItem[];\n\t/** Footer action used by items in this group. */\n\tactionLabel?: string;\n};\n\nexport type SearchCommandProps = {\n\tgroups: readonly SearchCommandGroup[];\n\t/** Controlled dialog state. */\n\topen?: boolean;\n\t/** Initial dialog state when uncontrolled. */\n\tdefaultOpen?: boolean;\n\tonOpenChange?: (open: boolean) => void;\n\tonItemSelect?: (item: SearchCommandItem) => void;\n\t/** Enables the configured modifier shortcut and slash. */\n\tenabledHotkeys?: boolean;\n\t/** Character used with Command or Control to open the menu. */\n\tshortcutKey?: string;\n\t/** Overrides the modifier displayed in the trigger. */\n\tshortcutModifier?: \"auto\" | \"command\" | \"control\";\n\ttriggerLabel?: string;\n\ttriggerSlot?: string;\n\tplaceholder?: string;\n\temptyMessage?: React.ReactNode;\n\ttitle?: string;\n\tdescription?: string;\n\tfooterIcon?: React.ReactNode;\n\tdefaultActionLabel?: string;\n\ttriggerClassName?: string;\n\tdialogClassName?: string;\n\tlistClassName?: string;\n};\n\nexport function SearchCommand({\n\tdefaultActionLabel = \"Open\",\n\tdefaultOpen = false,\n\tdescription = \"Search for a command to run...\",\n\tdialogClassName,\n\temptyMessage = \"No results found.\",\n\tenabledHotkeys = false,\n\tfooterIcon,\n\tgroups,\n\tlistClassName,\n\tonItemSelect,\n\tonOpenChange,\n\topen,\n\tplaceholder = \"Type a command or search…\",\n\tshortcutKey = \"k\",\n\tshortcutModifier = \"auto\",\n\ttitle = \"Command Palette\",\n\ttriggerClassName,\n\ttriggerLabel = \"Search…\",\n\ttriggerSlot = \"command-menu-trigger\",\n}: SearchCommandProps) {\n\tconst [internalOpen, setInternalOpen] = React.useState(defaultOpen);\n\tconst [selectedActionLabel, setSelectedActionLabel] =\n\t\tReact.useState(defaultActionLabel);\n\tconst isOpen = open ?? internalOpen;\n\tconst normalizedShortcutKey = shortcutKey.trim().toLowerCase();\n\tconst displayedShortcutKey = normalizedShortcutKey.toUpperCase();\n\tconst ariaKeyShortcuts =\n\t\tshortcutModifier === \"command\"\n\t\t\t? `Meta+${displayedShortcutKey} /`\n\t\t\t: shortcutModifier === \"control\"\n\t\t\t\t? `Control+${displayedShortcutKey} /`\n\t\t\t\t: `Meta+${displayedShortcutKey} Control+${displayedShortcutKey} /`;\n\n\tconst setOpen = React.useCallback(\n\t\t(nextOpen: boolean) => {\n\t\t\tif (open === undefined) setInternalOpen(nextOpen);\n\t\t\tonOpenChange?.(nextOpen);\n\t\t},\n\t\t[onOpenChange, open],\n\t);\n\n\tuseHotkeys(\n\t\t`mod+${normalizedShortcutKey}, slash`,\n\t\t(event) => {\n\t\t\tevent.preventDefault();\n\t\t\tsetOpen(!isOpen);\n\t\t},\n\t\t{ enabled: enabledHotkeys },\n\t);\n\n\tfunction handleItemSelect(item: SearchCommandItem) {\n\t\titem.onBeforeSelect?.();\n\t\tsetOpen(false);\n\t\titem.onSelect?.();\n\t\tonItemSelect?.(item);\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<Button\n\t\t\t\taria-expanded={isOpen}\n\t\t\t\taria-haspopup=\"dialog\"\n\t\t\t\taria-keyshortcuts={ariaKeyShortcuts}\n\t\t\t\taria-label={triggerLabel}\n\t\t\t\tclassName={cn(\n\t\t\t\t\t\"select-none gap-1.5 border-none px-1.5 text-muted-foreground will-change-[scale]\",\n\t\t\t\t\ttriggerClassName,\n\t\t\t\t)}\n\t\t\t\tdata-slot={triggerSlot}\n\t\t\t\tonClick={() => setOpen(true)}\n\t\t\t\tsize=\"sm\"\n\t\t\t\tvariant=\"ghost\"\n\t\t\t>\n\t\t\t\t<SearchIcon />\n\t\t\t\t<span className=\"font-medium font-sans text-sm/4 sm:hidden\">\n\t\t\t\t\t{triggerLabel}\n\t\t\t\t</span>\n\t\t\t\t{shortcutModifier !== \"control\" ? (\n\t\t\t\t\t<KbdGroup\n\t\t\t\t\t\tclassName={cn(\n\t\t\t\t\t\t\t\"hidden gap-0.75\",\n\t\t\t\t\t\t\tshortcutModifier === \"command\"\n\t\t\t\t\t\t\t\t? \"sm:flex\"\n\t\t\t\t\t\t\t\t: \"sm:in-[.os-macos_&]:flex\",\n\t\t\t\t\t\t)}\n\t\t\t\t\t>\n\t\t\t\t\t\t<Kbd className=\"w-5 min-w-auto\">⌘</Kbd>\n\t\t\t\t\t\t<Kbd className=\"w-5 min-w-auto\">{displayedShortcutKey}</Kbd>\n\t\t\t\t\t</KbdGroup>\n\t\t\t\t) : null}\n\t\t\t\t{shortcutModifier !== \"command\" ? (\n\t\t\t\t\t<KbdGroup\n\t\t\t\t\t\tclassName={cn(\n\t\t\t\t\t\t\t\"hidden gap-0.75\",\n\t\t\t\t\t\t\tshortcutModifier === \"control\"\n\t\t\t\t\t\t\t\t? \"sm:flex\"\n\t\t\t\t\t\t\t\t: \"sm:not-[.os-macos_&]:flex\",\n\t\t\t\t\t\t)}\n\t\t\t\t\t>\n\t\t\t\t\t\t<Kbd>Ctrl</Kbd>\n\t\t\t\t\t\t<Kbd className=\"w-5 min-w-auto\">{displayedShortcutKey}</Kbd>\n\t\t\t\t\t</KbdGroup>\n\t\t\t\t) : null}\n\t\t\t</Button>\n\n\t\t\t<CommandDialog\n\t\t\t\tclassName={dialogClassName}\n\t\t\t\tdescription={description}\n\t\t\t\tonOpenChange={setOpen}\n\t\t\t\topen={isOpen}\n\t\t\t\ttitle={title}\n\t\t\t>\n\t\t\t\t<SearchCommandInput placeholder={placeholder} />\n\n\t\t\t\t<div className=\"rounded-xl bg-background ring-1 ring-border\">\n\t\t\t\t\t<CommandList className={cn(\"scroll-fade min-h-80\", listClassName)}>\n\t\t\t\t\t\t<CommandEmpty>{emptyMessage}</CommandEmpty>\n\t\t\t\t\t\t{groups.map((group) => (\n\t\t\t\t\t\t\t<CommandGroup heading={group.heading} key={group.heading}>\n\t\t\t\t\t\t\t\t{group.items.map((item, index) => {\n\t\t\t\t\t\t\t\t\tconst actionLabel =\n\t\t\t\t\t\t\t\t\t\titem.actionLabel ?? group.actionLabel ?? defaultActionLabel;\n\t\t\t\t\t\t\t\t\tconst keywords = [\n\t\t\t\t\t\t\t\t\t\t...(item.keywords ?? []),\n\t\t\t\t\t\t\t\t\t\t...(item.description ? [item.description] : []),\n\t\t\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t<SearchCommandMenuItem\n\t\t\t\t\t\t\t\t\t\t\tdisabled={item.disabled}\n\t\t\t\t\t\t\t\t\t\t\tkey={item.id ?? `${item.value ?? item.title}-${index}`}\n\t\t\t\t\t\t\t\t\t\t\tkeywords={keywords.length > 0 ? keywords : undefined}\n\t\t\t\t\t\t\t\t\t\t\tonHighlight={() => setSelectedActionLabel(actionLabel)}\n\t\t\t\t\t\t\t\t\t\t\tonSelect={() => handleItemSelect(item)}\n\t\t\t\t\t\t\t\t\t\t\tvalue={item.value}\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t{item.icon ?? <CopyIcon />}\n\t\t\t\t\t\t\t\t\t\t\t<p className=\"line-clamp-1\">{item.title}</p>\n\t\t\t\t\t\t\t\t\t\t\t{item.meta ? (\n\t\t\t\t\t\t\t\t\t\t\t\t<span className=\"ml-auto font-mono font-normal text-muted-foreground text-xs tabular-nums max-sm:hidden\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t{item.meta}\n\t\t\t\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t\t\t\t) : null}\n\t\t\t\t\t\t\t\t\t\t\t{item.shortcut ? (\n\t\t\t\t\t\t\t\t\t\t\t\t<CommandShortcut className=\"font-mono tracking-[0.2em] max-sm:hidden\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t{item.shortcut}\n\t\t\t\t\t\t\t\t\t\t\t\t</CommandShortcut>\n\t\t\t\t\t\t\t\t\t\t\t) : null}\n\t\t\t\t\t\t\t\t\t\t</SearchCommandMenuItem>\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t})}\n\t\t\t\t\t\t\t</CommandGroup>\n\t\t\t\t\t\t))}\n\t\t\t\t\t</CommandList>\n\t\t\t\t</div>\n\n\t\t\t\t<div className=\"flex h-10\" />\n\t\t\t\t<div className=\"absolute inset-x-0 bottom-0 flex h-10 items-center justify-between gap-2 rounded-b-2xl px-4 font-medium text-xs\">\n\t\t\t\t\t<span className=\"size-4 shrink-0\">\n\t\t\t\t\t\t{footerIcon ?? <SearchIcon className=\"size-full\" />}\n\t\t\t\t\t</span>\n\t\t\t\t\t<div className=\"flex items-center gap-2 max-sm:hidden\">\n\t\t\t\t\t\t<span>{selectedActionLabel}</span>\n\t\t\t\t\t\t<Kbd>\n\t\t\t\t\t\t\t<CornerDownLeftIcon />\n\t\t\t\t\t\t</Kbd>\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t</CommandDialog>\n\t\t</>\n\t);\n}\n\nfunction SearchCommandInput({ placeholder }: { placeholder: string }) {\n\tconst [searchValue, setSearchValue] = React.useState(\"\");\n\n\treturn (\n\t\t<CommandInput\n\t\t\tplaceholder={placeholder}\n\t\t\tvalue={searchValue}\n\t\t\tonValueChange={setSearchValue}\n\t\t/>\n\t);\n}\n\nfunction SearchCommandMenuItem({\n\tchildren,\n\tonHighlight,\n\t...props\n}: React.ComponentProps<typeof CommandItem> & {\n\tonHighlight?: () => void;\n}) {\n\tconst ref = React.useRef<HTMLDivElement>(null);\n\n\tReact.useEffect(() => {\n\t\tconst commandItem = ref.current;\n\t\tif (!commandItem) return;\n\n\t\tconst observer = new MutationObserver(() => {\n\t\t\tif (commandItem.dataset.selected === \"true\") onHighlight?.();\n\t\t});\n\t\tobserver.observe(commandItem, {\n\t\t\tattributes: true,\n\t\t\tattributeFilter: [\"data-selected\"],\n\t\t});\n\n\t\treturn () => observer.disconnect();\n\t}, [onHighlight]);\n\n\treturn (\n\t\t<CommandItem ref={ref} {...props}>\n\t\t\t{children}\n\t\t</CommandItem>\n\t);\n}\n\nexport default SearchCommand;\n",
      "type": "registry:component",
      "target": "@components/search-command.tsx"
    }
  ],
  "meta": {
    "createdAt": "2026-07-30",
    "image": "https://cdn.tentui.com/images/components/search-command",
    "video": "https://cdn.tentui.com/videos/components/search-command"
  },
  "docs": "https://tentui.com/components/search-command",
  "categories": [
    "menus"
  ],
  "type": "registry:component"
}