{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "search-4",
  "title": "Autocomplete Search Input",
  "description": "Search input with an autocomplete dropdown of recent searches and keyboard navigable suggestions, an empty state, and a slash to focus hint.",
  "dependencies": [
    "@base-ui/react"
  ],
  "registryDependencies": [
    "kbd"
  ],
  "files": [
    {
      "path": "registry/blocks/search/4/search-block.tsx",
      "content": "\"use client\"\n\nimport { useMemo, useRef, useState } from \"react\"\nimport { cn } from \"@/lib/utils\"\nimport { Kbd } from \"@/components/ui/kbd\"\nimport { IconPlaceholder } from \"@/components/icons/icon-placeholder\"\n\ntype IconProps = { className?: string; size?: number | string }\n\ntype Suggestion = {\n  id: string\n  label: string\n  kind: \"recent\" | \"page\" | \"tag\"\n}\n\nconst RECENT: Suggestion[] = [\n  { id: \"r1\", label: \"Billing settings\", kind: \"recent\" },\n  { id: \"r2\", label: \"Invite teammates\", kind: \"recent\" },\n]\n\nconst SUGGESTIONS: Suggestion[] = [\n  { id: \"s1\", label: \"Getting started guide\", kind: \"page\" },\n  { id: \"s2\", label: \"API reference\", kind: \"page\" },\n  { id: \"s3\", label: \"Webhooks\", kind: \"tag\" },\n  { id: \"s4\", label: \"Two-factor authentication\", kind: \"page\" },\n  { id: \"s5\", label: \"Export data\", kind: \"tag\" },\n  { id: \"s6\", label: \"Keyboard shortcuts\", kind: \"page\" },\n]\n\nconst iconFor = {\n  recent: (p: IconProps) => (\n    <IconPlaceholder\n      lucide=\"Clock\"\n      tabler=\"IconClock\"\n      hugeicons=\"TimeIcon\"\n      phosphor=\"Clock\"\n      remixicon=\"RiTimeLine\"\n      {...p}\n    />\n  ),\n  page: (p: IconProps) => (\n    <IconPlaceholder\n      lucide=\"FileText\"\n      tabler=\"IconFileText\"\n      hugeicons=\"Task01Icon\"\n      phosphor=\"FileText\"\n      remixicon=\"RiFileList2Line\"\n      {...p}\n    />\n  ),\n  tag: (p: IconProps) => (\n    <IconPlaceholder\n      lucide=\"Hash\"\n      tabler=\"IconHash\"\n      hugeicons=\"HashIcon\"\n      phosphor=\"Hash\"\n      remixicon=\"RiHashtag\"\n      {...p}\n    />\n  ),\n}\n\nexport default function SearchBlock() {\n  const [query, setQuery] = useState(\"\")\n  const [open, setOpen] = useState(false)\n  const [active, setActive] = useState(0)\n  const inputRef = useRef<HTMLInputElement>(null)\n\n  const results = useMemo(() => {\n    const q = query.trim().toLowerCase()\n    if (!q) return RECENT\n    return SUGGESTIONS.filter((item) => item.label.toLowerCase().includes(q))\n  }, [query])\n\n  function handleKeyDown(event: React.KeyboardEvent<HTMLInputElement>) {\n    if (!open || results.length === 0) return\n    if (event.key === \"ArrowDown\") {\n      event.preventDefault()\n      setActive((index) => (index + 1) % results.length)\n    } else if (event.key === \"ArrowUp\") {\n      event.preventDefault()\n      setActive((index) => (index - 1 + results.length) % results.length)\n    } else if (event.key === \"Enter\") {\n      event.preventDefault()\n      const picked = results[active]\n      if (picked) {\n        setQuery(picked.label)\n        setOpen(false)\n      }\n    } else if (event.key === \"Escape\") {\n      setOpen(false)\n    }\n  }\n\n  return (\n    <section className=\"flex min-h-svh w-full items-start justify-center bg-background px-6 py-24 text-foreground\">\n      <div className=\"w-full max-w-md\">\n        <div className=\"relative\">\n          <div className=\"relative\">\n            <IconPlaceholder\n              lucide=\"Search\"\n              tabler=\"IconSearch\"\n              hugeicons=\"SearchIcon\"\n              phosphor=\"MagnifyingGlass\"\n              remixicon=\"RiSearchLine\"\n              className=\"pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2 text-muted-foreground\"\n              aria-hidden=\"true\"\n            />\n            <input\n              ref={inputRef}\n              type=\"search\"\n              value={query}\n              placeholder=\"Search docs, pages, and settings…\"\n              aria-label=\"Search\"\n              aria-expanded={open}\n              aria-controls=\"search-suggestions\"\n              role=\"combobox\"\n              autoComplete=\"off\"\n              className=\"h-11 w-full rounded-lg border border-border bg-background pr-16 pl-9 text-sm transition-colors outline-none placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-1 focus-visible:ring-ring/50 [&::-webkit-search-cancel-button]:hidden\"\n              onFocus={() => setOpen(true)}\n              onBlur={() => setTimeout(() => setOpen(false), 120)}\n              onChange={(event) => {\n                setQuery(event.target.value)\n                setActive(0)\n                setOpen(true)\n              }}\n              onKeyDown={handleKeyDown}\n            />\n            <Kbd className=\"absolute top-1/2 right-3 -translate-y-1/2\">/</Kbd>\n          </div>\n\n          {open && (\n            <div\n              id=\"search-suggestions\"\n              role=\"listbox\"\n              className=\"absolute z-10 mt-1.5 w-full rounded-lg border border-border bg-popover shadow-md\"\n            >\n              <p className=\"px-3 pt-2.5 pb-1 text-[10px] font-semibold tracking-widest text-muted-foreground uppercase\">\n                {query.trim() ? \"Suggestions\" : \"Recent\"}\n              </p>\n              {results.length > 0 ? (\n                <ul className=\"pb-1.5\">\n                  {results.map((item, index) => {\n                    const Icon = iconFor[item.kind]\n                    return (\n                      <li key={item.id}>\n                        <button\n                          type=\"button\"\n                          role=\"option\"\n                          aria-selected={index === active}\n                          className={cn(\n                            \"flex w-full items-center gap-2.5 px-3 py-2 text-left text-sm transition-colors\",\n                            index === active\n                              ? \"bg-muted text-foreground\"\n                              : \"text-muted-foreground hover:bg-muted/60\"\n                          )}\n                          onMouseEnter={() => setActive(index)}\n                          onMouseDown={(event) => {\n                            event.preventDefault()\n                            setQuery(item.label)\n                            setOpen(false)\n                          }}\n                        >\n                          <Icon\n                            className=\"size-4 shrink-0 text-muted-foreground\"\n                            aria-hidden=\"true\"\n                          />\n                          <span className=\"flex-1 truncate text-foreground\">\n                            {item.label}\n                          </span>\n                          <IconPlaceholder\n                            lucide=\"ArrowUpRight\"\n                            tabler=\"IconArrowUpRight\"\n                            hugeicons=\"ArrowUpRightIcon\"\n                            phosphor=\"ArrowUpRight\"\n                            remixicon=\"RiArrowRightUpLine\"\n                            className=\"size-3.5 shrink-0 text-muted-foreground/60\"\n                            aria-hidden=\"true\"\n                          />\n                        </button>\n                      </li>\n                    )\n                  })}\n                </ul>\n              ) : (\n                <p className=\"px-3 py-6 text-center text-sm text-muted-foreground\">\n                  No results for &ldquo;{query}&rdquo;\n                </p>\n              )}\n            </div>\n          )}\n        </div>\n        <p className=\"mt-3 text-center text-xs text-muted-foreground\">\n          Press <Kbd>/</Kbd> to focus, <Kbd>↑</Kbd> <Kbd>↓</Kbd> to navigate,{\" \"}\n          <Kbd>Enter</Kbd> to select.\n        </p>\n      </div>\n    </section>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/blocks/search-4.tsx"
    }
  ],
  "meta": {
    "height": "276px",
    "tier": "free"
  },
  "categories": [
    "search"
  ],
  "type": "registry:block"
}