{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"react-select-dropdown-collection-with-searchable-combobox-multi-select-async-options-and-keyboard-support","type":"registry:block","title":"React Select Dropdown Collection with Searchable Combobox, Multi Select, Async Options and Keyboard Support","description":"Free React select components with Tailwind and no package: searchable combobox, multi-select, chips, async options and grouped lists with full keyboard support.","dependencies":[],"files":[{"path":"components/we-inc/react-select-dropdown-collection-with-searchable-combobox-multi-select-async-options-and-keyboard-support.tsx","type":"registry:component","content":"import { useEffect, useRef, useState, type KeyboardEvent, type ReactElement } from \"react\";\n\n/*\n  Every piece below is written once: the function renders the live demo and the\n  string next to it is that same source file, so the code you copy is the code you see.\n*/\n\ntype Lang = \"react\" | \"html\";\ntype Piece = {\n  id: string;\n  name: string;\n  blurb: string;\n  group: string;\n  Demo: () => ReactElement;\n  react: string;\n  html?: string;\n  stage: string;\n};\n\nconst r1Demo = (() => {\nconst STATUSES = [\n  { label: \"Backlog\", dot: \"bg-stone-400\" },\n  { label: \"Planned\", dot: \"bg-sky-500\" },\n  { label: \"In progress\", dot: \"bg-amber-500\" },\n  { label: \"In review\", dot: \"bg-violet-500\" },\n  { label: \"Done\", dot: \"bg-emerald-500\" },\n  { label: \"Cancelled\", dot: \"bg-rose-500\" },\n];\n\n// Select-only combobox from the WAI-ARIA Authoring Practices: focus stays on the\n// combobox and aria-activedescendant points at the highlighted option.\nfunction SelectOnlyCombobox() {\n  const [value, setValue] = useState(2);\n  const [open, setOpen] = useState(false);\n  const [active, setActive] = useState(2);\n  const rootRef = useRef<HTMLDivElement>(null);\n  const typed = useRef({ text: \"\", at: 0 });\n\n  useEffect(() => {\n    if (!open) return;\n    const close = (e: MouseEvent) => !rootRef.current?.contains(e.target as Node) && setOpen(false);\n    document.addEventListener(\"mousedown\", close);\n    return () => document.removeEventListener(\"mousedown\", close);\n  }, [open]);\n\n  function choose(i: number) {\n    setValue(i);\n    setActive(i);\n    setOpen(false);\n  }\n\n  function onKeyDown(e: KeyboardEvent<HTMLDivElement>) {\n    const last = STATUSES.length - 1;\n    if (!open) {\n      if ([\"ArrowDown\", \"ArrowUp\", \"Enter\", \" \"].includes(e.key)) {\n        e.preventDefault();\n        setActive(value);\n        setOpen(true);\n      }\n      return;\n    }\n    if (e.key === \"ArrowDown\") setActive(Math.min(last, active + 1));\n    else if (e.key === \"ArrowUp\") setActive(Math.max(0, active - 1));\n    else if (e.key === \"Home\") setActive(0);\n    else if (e.key === \"End\") setActive(last);\n    else if (e.key === \"Enter\" || e.key === \" \") choose(active);\n    else if (e.key === \"Escape\") setOpen(false);\n    else if (e.key === \"Tab\") return choose(active);\n    else if (e.key.length === 1) {\n      // Type-ahead: jump to the first option starting with the typed letters.\n      const now = Date.now();\n      typed.current = { text: (now - typed.current.at < 600 ? typed.current.text : \"\") + e.key.toLowerCase(), at: now };\n      const hit = STATUSES.findIndex((s) => s.label.toLowerCase().startsWith(typed.current.text));\n      if (hit >= 0) setActive(hit);\n    } else return;\n    e.preventDefault();\n  }\n\n  return (\n    <div ref={rootRef} className=\"relative w-full max-w-[15rem]\">\n      <span id=\"status-label\" className=\"block text-sm font-semibold text-slate-900\">\n        Status\n      </span>\n      <div\n        role=\"combobox\"\n        tabIndex={0}\n        aria-labelledby=\"status-label\"\n        aria-haspopup=\"listbox\"\n        aria-expanded={open}\n        aria-controls=\"status-listbox\"\n        aria-activedescendant={open ? `status-opt-${active}` : undefined}\n        onClick={() => (open ? setOpen(false) : (setActive(value), setOpen(true)))}\n        onKeyDown={onKeyDown}\n        className=\"mt-2 flex h-11 cursor-pointer items-center gap-2 rounded-lg border border-slate-300 bg-white px-3 text-sm text-slate-900 shadow-sm focus-visible:border-sky-600 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-sky-600/30\"\n      >\n        <span aria-hidden=\"true\" className={`h-2 w-2 rounded-full ${STATUSES[value].dot}`} />\n        <span className=\"flex-1\">{STATUSES[value].label}</span>\n        <svg viewBox=\"0 0 20 20\" aria-hidden=\"true\" className={`h-4 w-4 fill-none stroke-slate-500 transition-transform ${open ? \"rotate-180\" : \"\"}`} strokeWidth={2} strokeLinecap=\"round\" strokeLinejoin=\"round\">\n          <path d=\"M6 8l4 4 4-4\" />\n        </svg>\n      </div>\n      {open && (\n        <ul id=\"status-listbox\" role=\"listbox\" aria-labelledby=\"status-label\" className=\"absolute z-20 mt-1 w-full rounded-lg border border-slate-200 bg-white py-1 shadow-lg\">\n          {STATUSES.map((s, i) => (\n            <li\n              key={s.label}\n              id={`status-opt-${i}`}\n              role=\"option\"\n              aria-selected={i === value}\n              onMouseDown={(e) => e.preventDefault()}\n              onClick={() => choose(i)}\n              onMouseEnter={() => setActive(i)}\n              className={`flex h-10 cursor-pointer items-center gap-2 px-3 text-sm text-slate-800 ${i === active ? \"bg-sky-50\" : \"\"}`}\n            >\n              <span aria-hidden=\"true\" className={`h-2 w-2 rounded-full ${s.dot}`} />\n              <span className=\"flex-1\">{s.label}</span>\n              {i === value && (\n                <svg viewBox=\"0 0 20 20\" aria-hidden=\"true\" className=\"h-4 w-4 fill-none stroke-sky-700\" strokeWidth={2} strokeLinecap=\"round\" strokeLinejoin=\"round\">\n                  <path d=\"M5 10.5l3.5 3.5L15 7\" />\n                </svg>\n              )}\n            </li>\n          ))}\n        </ul>\n      )}\n    </div>\n  );\n}\n  return SelectOnlyCombobox;\n})();\nconst r1React = \"import { useEffect, useRef, useState, type KeyboardEvent } from \\\"react\\\";\\n\\nconst STATUSES = [\\n  { label: \\\"Backlog\\\", dot: \\\"bg-stone-400\\\" },\\n  { label: \\\"Planned\\\", dot: \\\"bg-sky-500\\\" },\\n  { label: \\\"In progress\\\", dot: \\\"bg-amber-500\\\" },\\n  { label: \\\"In review\\\", dot: \\\"bg-violet-500\\\" },\\n  { label: \\\"Done\\\", dot: \\\"bg-emerald-500\\\" },\\n  { label: \\\"Cancelled\\\", dot: \\\"bg-rose-500\\\" },\\n];\\n\\n// Select-only combobox from the WAI-ARIA Authoring Practices: focus stays on the\\n// combobox and aria-activedescendant points at the highlighted option.\\nexport default function SelectOnlyCombobox() {\\n  const [value, setValue] = useState(2);\\n  const [open, setOpen] = useState(false);\\n  const [active, setActive] = useState(2);\\n  const rootRef = useRef<HTMLDivElement>(null);\\n  const typed = useRef({ text: \\\"\\\", at: 0 });\\n\\n  useEffect(() => {\\n    if (!open) return;\\n    const close = (e: MouseEvent) => !rootRef.current?.contains(e.target as Node) && setOpen(false);\\n    document.addEventListener(\\\"mousedown\\\", close);\\n    return () => document.removeEventListener(\\\"mousedown\\\", close);\\n  }, [open]);\\n\\n  function choose(i: number) {\\n    setValue(i);\\n    setActive(i);\\n    setOpen(false);\\n  }\\n\\n  function onKeyDown(e: KeyboardEvent<HTMLDivElement>) {\\n    const last = STATUSES.length - 1;\\n    if (!open) {\\n      if ([\\\"ArrowDown\\\", \\\"ArrowUp\\\", \\\"Enter\\\", \\\" \\\"].includes(e.key)) {\\n        e.preventDefault();\\n        setActive(value);\\n        setOpen(true);\\n      }\\n      return;\\n    }\\n    if (e.key === \\\"ArrowDown\\\") setActive(Math.min(last, active + 1));\\n    else if (e.key === \\\"ArrowUp\\\") setActive(Math.max(0, active - 1));\\n    else if (e.key === \\\"Home\\\") setActive(0);\\n    else if (e.key === \\\"End\\\") setActive(last);\\n    else if (e.key === \\\"Enter\\\" || e.key === \\\" \\\") choose(active);\\n    else if (e.key === \\\"Escape\\\") setOpen(false);\\n    else if (e.key === \\\"Tab\\\") return choose(active);\\n    else if (e.key.length === 1) {\\n      // Type-ahead: jump to the first option starting with the typed letters.\\n      const now = Date.now();\\n      typed.current = { text: (now - typed.current.at < 600 ? typed.current.text : \\\"\\\") + e.key.toLowerCase(), at: now };\\n      const hit = STATUSES.findIndex((s) => s.label.toLowerCase().startsWith(typed.current.text));\\n      if (hit >= 0) setActive(hit);\\n    } else return;\\n    e.preventDefault();\\n  }\\n\\n  return (\\n    <div ref={rootRef} className=\\\"relative w-full max-w-[15rem]\\\">\\n      <span id=\\\"status-label\\\" className=\\\"block text-sm font-semibold text-slate-900\\\">\\n        Status\\n      </span>\\n      <div\\n        role=\\\"combobox\\\"\\n        tabIndex={0}\\n        aria-labelledby=\\\"status-label\\\"\\n        aria-haspopup=\\\"listbox\\\"\\n        aria-expanded={open}\\n        aria-controls=\\\"status-listbox\\\"\\n        aria-activedescendant={open ? `status-opt-${active}` : undefined}\\n        onClick={() => (open ? setOpen(false) : (setActive(value), setOpen(true)))}\\n        onKeyDown={onKeyDown}\\n        className=\\\"mt-2 flex h-11 cursor-pointer items-center gap-2 rounded-lg border border-slate-300 bg-white px-3 text-sm text-slate-900 shadow-sm focus-visible:border-sky-600 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-sky-600/30\\\"\\n      >\\n        <span aria-hidden=\\\"true\\\" className={`h-2 w-2 rounded-full ${STATUSES[value].dot}`} />\\n        <span className=\\\"flex-1\\\">{STATUSES[value].label}</span>\\n        <svg viewBox=\\\"0 0 20 20\\\" aria-hidden=\\\"true\\\" className={`h-4 w-4 fill-none stroke-slate-500 transition-transform ${open ? \\\"rotate-180\\\" : \\\"\\\"}`} strokeWidth={2} strokeLinecap=\\\"round\\\" strokeLinejoin=\\\"round\\\">\\n          <path d=\\\"M6 8l4 4 4-4\\\" />\\n        </svg>\\n      </div>\\n      {open && (\\n        <ul id=\\\"status-listbox\\\" role=\\\"listbox\\\" aria-labelledby=\\\"status-label\\\" className=\\\"absolute z-20 mt-1 w-full rounded-lg border border-slate-200 bg-white py-1 shadow-lg\\\">\\n          {STATUSES.map((s, i) => (\\n            <li\\n              key={s.label}\\n              id={`status-opt-${i}`}\\n              role=\\\"option\\\"\\n              aria-selected={i === value}\\n              onMouseDown={(e) => e.preventDefault()}\\n              onClick={() => choose(i)}\\n              onMouseEnter={() => setActive(i)}\\n              className={`flex h-10 cursor-pointer items-center gap-2 px-3 text-sm text-slate-800 ${i === active ? \\\"bg-sky-50\\\" : \\\"\\\"}`}\\n            >\\n              <span aria-hidden=\\\"true\\\" className={`h-2 w-2 rounded-full ${s.dot}`} />\\n              <span className=\\\"flex-1\\\">{s.label}</span>\\n              {i === value && (\\n                <svg viewBox=\\\"0 0 20 20\\\" aria-hidden=\\\"true\\\" className=\\\"h-4 w-4 fill-none stroke-sky-700\\\" strokeWidth={2} strokeLinecap=\\\"round\\\" strokeLinejoin=\\\"round\\\">\\n                  <path d=\\\"M5 10.5l3.5 3.5L15 7\\\" />\\n                </svg>\\n              )}\\n            </li>\\n          ))}\\n        </ul>\\n      )}\\n    </div>\\n  );\\n}\\n\";\n\nconst r2Demo = (() => {\nconst PEOPLE = [\n  { name: \"Maya Lindqvist\", role: \"Design lead\" },\n  { name: \"Marcus Oyelaran\", role: \"Backend\" },\n  { name: \"Priya Raman\", role: \"Product\" },\n  { name: \"Tomás Herrera\", role: \"Frontend\" },\n  { name: \"Amara Osei\", role: \"Support\" },\n  { name: \"Jonah Feld\", role: \"Data\" },\n  { name: \"Lena Marsh\", role: \"Marketing\" },\n];\n\n// Editable combobox with list autocomplete (WAI-ARIA Authoring Practices pattern).\nfunction SearchableCombobox() {\n  const [query, setQuery] = useState(\"ma\");\n  const [selected, setSelected] = useState(\"\");\n  const [open, setOpen] = useState(true);\n  const [active, setActive] = useState(0);\n  const rootRef = useRef<HTMLDivElement>(null);\n  const listRef = useRef<HTMLUListElement>(null);\n\n  const results = PEOPLE.filter((p) => p.name.toLowerCase().includes(query.trim().toLowerCase()));\n\n  useEffect(() => {\n    const close = (e: MouseEvent) => !rootRef.current?.contains(e.target as Node) && setOpen(false);\n    document.addEventListener(\"mousedown\", close);\n    return () => document.removeEventListener(\"mousedown\", close);\n  }, []);\n\n  // Keep the highlighted option visible inside the list without scrolling the page.\n  useEffect(() => {\n    const list = listRef.current;\n    const el = list?.querySelector<HTMLElement>(`[data-i=\"${active}\"]`);\n    if (!list || !el) return;\n    if (el.offsetTop < list.scrollTop) list.scrollTop = el.offsetTop;\n    else if (el.offsetTop + el.offsetHeight > list.scrollTop + list.clientHeight) list.scrollTop = el.offsetTop + el.offsetHeight - list.clientHeight;\n  }, [active]);\n\n  function pick(name: string) {\n    setSelected(name);\n    setQuery(name);\n    setOpen(false);\n  }\n\n  function onKeyDown(e: KeyboardEvent<HTMLInputElement>) {\n    if (e.key === \"ArrowDown\") {\n      if (open) setActive(Math.min(results.length - 1, active + 1));\n      else setOpen(true);\n    } else if (e.key === \"ArrowUp\") {\n      if (open) setActive(Math.max(0, active - 1));\n    } else if (e.key === \"Enter\" && open && results[active]) pick(results[active].name);\n    else if (e.key === \"Escape\") {\n      if (open) setOpen(false);\n      else setQuery(\"\");\n    } else return;\n    e.preventDefault();\n  }\n\n  const bold = (name: string) => {\n    const i = name.toLowerCase().indexOf(query.trim().toLowerCase());\n    if (!query.trim() || i < 0) return name;\n    const n = query.trim().length;\n    return (\n      <>\n        {name.slice(0, i)}\n        <strong className=\"font-semibold text-slate-950\">{name.slice(i, i + n)}</strong>\n        {name.slice(i + n)}\n      </>\n    );\n  };\n\n  return (\n    <div ref={rootRef} className=\"relative w-full max-w-[16rem]\">\n      <label htmlFor=\"assignee\" className=\"block text-sm font-semibold text-slate-900\">\n        Assign to\n      </label>\n      <div className=\"relative mt-2\">\n        <svg viewBox=\"0 0 20 20\" aria-hidden=\"true\" className=\"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 fill-none stroke-slate-500\" strokeWidth={2} strokeLinecap=\"round\">\n          <circle cx=\"9\" cy=\"9\" r=\"5.5\" />\n          <path d=\"M13 13l3.5 3.5\" />\n        </svg>\n        <input\n          id=\"assignee\"\n          type=\"text\"\n          role=\"combobox\"\n          autoComplete=\"off\"\n          aria-autocomplete=\"list\"\n          aria-expanded={open}\n          aria-controls=\"assignee-list\"\n          aria-activedescendant={open && results[active] ? `assignee-${active}` : undefined}\n          value={query}\n          placeholder=\"Search teammates\"\n          onChange={(e) => {\n            setQuery(e.target.value);\n            setActive(0);\n            setOpen(true);\n          }}\n          onClick={() => setOpen(true)}\n          onKeyDown={onKeyDown}\n          className=\"h-11 w-full rounded-lg border border-slate-300 bg-white pl-9 pr-3 text-base text-slate-900 placeholder:text-slate-500 focus:border-sky-600 focus:outline-none focus:ring-2 focus:ring-sky-600/30 sm:text-sm\"\n        />\n      </div>\n      {open && (\n        <ul ref={listRef} id=\"assignee-list\" role=\"listbox\" aria-label=\"Teammates\" className=\"absolute z-20 mt-1 max-h-52 w-full overflow-auto rounded-lg border border-slate-200 bg-white py-1 shadow-lg\">\n          {results.map((p, i) => (\n            <li\n              key={p.name}\n              id={`assignee-${i}`}\n              data-i={i}\n              role=\"option\"\n              aria-selected={p.name === selected}\n              onMouseDown={(e) => e.preventDefault()}\n              onClick={() => pick(p.name)}\n              onMouseEnter={() => setActive(i)}\n              className={`flex cursor-pointer items-center gap-2.5 px-3 py-2 text-sm text-slate-700 ${i === active ? \"bg-sky-50\" : \"\"}`}\n            >\n              <span aria-hidden=\"true\" className=\"grid h-7 w-7 shrink-0 place-items-center rounded-full bg-slate-200 text-[11px] font-semibold text-slate-700\">\n                {p.name.split(\" \").map((w) => w[0]).join(\"\")}\n              </span>\n              <span className=\"min-w-0\">\n                <span className=\"block truncate\">{bold(p.name)}</span>\n                <span className=\"block text-xs text-slate-500\">{p.role}</span>\n              </span>\n            </li>\n          ))}\n          {results.length === 0 && <li className=\"px-3 py-2 text-sm text-slate-600\">No teammate matches \"{query}\"</li>}\n        </ul>\n      )}\n    </div>\n  );\n}\n  return SearchableCombobox;\n})();\nconst r2React = \"import { useEffect, useRef, useState, type KeyboardEvent } from \\\"react\\\";\\n\\nconst PEOPLE = [\\n  { name: \\\"Maya Lindqvist\\\", role: \\\"Design lead\\\" },\\n  { name: \\\"Marcus Oyelaran\\\", role: \\\"Backend\\\" },\\n  { name: \\\"Priya Raman\\\", role: \\\"Product\\\" },\\n  { name: \\\"Tomás Herrera\\\", role: \\\"Frontend\\\" },\\n  { name: \\\"Amara Osei\\\", role: \\\"Support\\\" },\\n  { name: \\\"Jonah Feld\\\", role: \\\"Data\\\" },\\n  { name: \\\"Lena Marsh\\\", role: \\\"Marketing\\\" },\\n];\\n\\n// Editable combobox with list autocomplete (WAI-ARIA Authoring Practices pattern).\\nexport default function SearchableCombobox() {\\n  const [query, setQuery] = useState(\\\"ma\\\");\\n  const [selected, setSelected] = useState(\\\"\\\");\\n  const [open, setOpen] = useState(true);\\n  const [active, setActive] = useState(0);\\n  const rootRef = useRef<HTMLDivElement>(null);\\n  const listRef = useRef<HTMLUListElement>(null);\\n\\n  const results = PEOPLE.filter((p) => p.name.toLowerCase().includes(query.trim().toLowerCase()));\\n\\n  useEffect(() => {\\n    const close = (e: MouseEvent) => !rootRef.current?.contains(e.target as Node) && setOpen(false);\\n    document.addEventListener(\\\"mousedown\\\", close);\\n    return () => document.removeEventListener(\\\"mousedown\\\", close);\\n  }, []);\\n\\n  // Keep the highlighted option visible inside the list without scrolling the page.\\n  useEffect(() => {\\n    const list = listRef.current;\\n    const el = list?.querySelector<HTMLElement>(`[data-i=\\\"${active}\\\"]`);\\n    if (!list || !el) return;\\n    if (el.offsetTop < list.scrollTop) list.scrollTop = el.offsetTop;\\n    else if (el.offsetTop + el.offsetHeight > list.scrollTop + list.clientHeight) list.scrollTop = el.offsetTop + el.offsetHeight - list.clientHeight;\\n  }, [active]);\\n\\n  function pick(name: string) {\\n    setSelected(name);\\n    setQuery(name);\\n    setOpen(false);\\n  }\\n\\n  function onKeyDown(e: KeyboardEvent<HTMLInputElement>) {\\n    if (e.key === \\\"ArrowDown\\\") {\\n      if (open) setActive(Math.min(results.length - 1, active + 1));\\n      else setOpen(true);\\n    } else if (e.key === \\\"ArrowUp\\\") {\\n      if (open) setActive(Math.max(0, active - 1));\\n    } else if (e.key === \\\"Enter\\\" && open && results[active]) pick(results[active].name);\\n    else if (e.key === \\\"Escape\\\") {\\n      if (open) setOpen(false);\\n      else setQuery(\\\"\\\");\\n    } else return;\\n    e.preventDefault();\\n  }\\n\\n  const bold = (name: string) => {\\n    const i = name.toLowerCase().indexOf(query.trim().toLowerCase());\\n    if (!query.trim() || i < 0) return name;\\n    const n = query.trim().length;\\n    return (\\n      <>\\n        {name.slice(0, i)}\\n        <strong className=\\\"font-semibold text-slate-950\\\">{name.slice(i, i + n)}</strong>\\n        {name.slice(i + n)}\\n      </>\\n    );\\n  };\\n\\n  return (\\n    <div ref={rootRef} className=\\\"relative w-full max-w-[16rem]\\\">\\n      <label htmlFor=\\\"assignee\\\" className=\\\"block text-sm font-semibold text-slate-900\\\">\\n        Assign to\\n      </label>\\n      <div className=\\\"relative mt-2\\\">\\n        <svg viewBox=\\\"0 0 20 20\\\" aria-hidden=\\\"true\\\" className=\\\"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 fill-none stroke-slate-500\\\" strokeWidth={2} strokeLinecap=\\\"round\\\">\\n          <circle cx=\\\"9\\\" cy=\\\"9\\\" r=\\\"5.5\\\" />\\n          <path d=\\\"M13 13l3.5 3.5\\\" />\\n        </svg>\\n        <input\\n          id=\\\"assignee\\\"\\n          type=\\\"text\\\"\\n          role=\\\"combobox\\\"\\n          autoComplete=\\\"off\\\"\\n          aria-autocomplete=\\\"list\\\"\\n          aria-expanded={open}\\n          aria-controls=\\\"assignee-list\\\"\\n          aria-activedescendant={open && results[active] ? `assignee-${active}` : undefined}\\n          value={query}\\n          placeholder=\\\"Search teammates\\\"\\n          onChange={(e) => {\\n            setQuery(e.target.value);\\n            setActive(0);\\n            setOpen(true);\\n          }}\\n          onClick={() => setOpen(true)}\\n          onKeyDown={onKeyDown}\\n          className=\\\"h-11 w-full rounded-lg border border-slate-300 bg-white pl-9 pr-3 text-base text-slate-900 placeholder:text-slate-500 focus:border-sky-600 focus:outline-none focus:ring-2 focus:ring-sky-600/30 sm:text-sm\\\"\\n        />\\n      </div>\\n      {open && (\\n        <ul ref={listRef} id=\\\"assignee-list\\\" role=\\\"listbox\\\" aria-label=\\\"Teammates\\\" className=\\\"absolute z-20 mt-1 max-h-52 w-full overflow-auto rounded-lg border border-slate-200 bg-white py-1 shadow-lg\\\">\\n          {results.map((p, i) => (\\n            <li\\n              key={p.name}\\n              id={`assignee-${i}`}\\n              data-i={i}\\n              role=\\\"option\\\"\\n              aria-selected={p.name === selected}\\n              onMouseDown={(e) => e.preventDefault()}\\n              onClick={() => pick(p.name)}\\n              onMouseEnter={() => setActive(i)}\\n              className={`flex cursor-pointer items-center gap-2.5 px-3 py-2 text-sm text-slate-700 ${i === active ? \\\"bg-sky-50\\\" : \\\"\\\"}`}\\n            >\\n              <span aria-hidden=\\\"true\\\" className=\\\"grid h-7 w-7 shrink-0 place-items-center rounded-full bg-slate-200 text-[11px] font-semibold text-slate-700\\\">\\n                {p.name.split(\\\" \\\").map((w) => w[0]).join(\\\"\\\")}\\n              </span>\\n              <span className=\\\"min-w-0\\\">\\n                <span className=\\\"block truncate\\\">{bold(p.name)}</span>\\n                <span className=\\\"block text-xs text-slate-500\\\">{p.role}</span>\\n              </span>\\n            </li>\\n          ))}\\n          {results.length === 0 && <li className=\\\"px-3 py-2 text-sm text-slate-600\\\">No teammate matches \\\"{query}\\\"</li>}\\n        </ul>\\n      )}\\n    </div>\\n  );\\n}\\n\";\n\nconst r5Demo = (() => {\nconst CITIES = [\"Lisbon, Portugal\", \"Lima, Peru\", \"Lille, France\", \"Lyon, France\", \"Leeds, United Kingdom\", \"Linz, Austria\", \"Ljubljana, Slovenia\", \"Lagos, Nigeria\", \"Oslo, Norway\", \"Osaka, Japan\"];\n\n// Stand-in for a network call. Replace the body with your own request and keep the abort signal.\nfunction searchCities(q: string, signal: AbortSignal): Promise<string[]> {\n  return new Promise((resolve, reject) => {\n    const id = setTimeout(() => resolve(CITIES.filter((c) => c.toLowerCase().startsWith(q.toLowerCase()))), 500);\n    signal.addEventListener(\"abort\", () => {\n      clearTimeout(id);\n      reject(new DOMException(\"aborted\", \"AbortError\"));\n    });\n  });\n}\n\nfunction AsyncCombobox() {\n  const [query, setQuery] = useState(\"li\");\n  const [results, setResults] = useState<string[]>([]);\n  const [loading, setLoading] = useState(false);\n  const [open, setOpen] = useState(true);\n  const [active, setActive] = useState(0);\n\n  // Debounce 250ms, cancel the previous request, then load.\n  useEffect(() => {\n    if (query.trim().length < 2) {\n      setResults([]);\n      setLoading(false);\n      return;\n    }\n    const ac = new AbortController();\n    setLoading(true);\n    const t = setTimeout(() => {\n      searchCities(query.trim(), ac.signal)\n        .then((r) => {\n          setResults(r);\n          setActive(0);\n          setLoading(false);\n        })\n        .catch(() => {});\n    }, 250);\n    return () => {\n      clearTimeout(t);\n      ac.abort();\n    };\n  }, [query]);\n\n  function onKeyDown(e: KeyboardEvent<HTMLInputElement>) {\n    if (e.key === \"ArrowDown\") (open ? setActive(Math.min(results.length - 1, active + 1)) : setOpen(true));\n    else if (e.key === \"ArrowUp\") setActive(Math.max(0, active - 1));\n    else if (e.key === \"Enter\" && open && results[active]) {\n      setQuery(results[active]);\n      setOpen(false);\n    } else if (e.key === \"Escape\") setOpen(false);\n    else return;\n    e.preventDefault();\n  }\n\n  const message = query.trim().length < 2 ? \"Type at least 2 letters\" : loading ? \"Searching\" : results.length ? `${results.length} cities found` : \"No cities match\";\n\n  return (\n    <div className=\"relative w-full max-w-[16rem]\" onBlur={(e) => !e.currentTarget.contains(e.relatedTarget) && setOpen(false)}>\n      <label htmlFor=\"city\" className=\"block text-sm font-semibold text-slate-900\">\n        Office city\n      </label>\n      <div className=\"relative mt-2\">\n        <input\n          id=\"city\"\n          type=\"text\"\n          role=\"combobox\"\n          autoComplete=\"off\"\n          aria-autocomplete=\"list\"\n          aria-expanded={open}\n          aria-controls=\"city-list\"\n          aria-activedescendant={open && !loading && results[active] ? `city-${active}` : undefined}\n          aria-describedby=\"city-status\"\n          value={query}\n          onChange={(e) => {\n            setQuery(e.target.value);\n            setOpen(true);\n          }}\n          onFocus={() => setOpen(true)}\n          onKeyDown={onKeyDown}\n          className=\"h-11 w-full rounded-lg border border-slate-300 bg-white px-3 pr-9 text-base text-slate-900 focus:border-sky-600 focus:outline-none focus:ring-2 focus:ring-sky-600/30 sm:text-sm\"\n        />\n        {loading && <span aria-hidden=\"true\" className=\"absolute right-3 top-1/2 h-4 w-4 -translate-y-1/2 animate-spin rounded-full border-2 border-slate-300 border-t-sky-600 motion-reduce:animate-none\" />}\n      </div>\n      <p id=\"city-status\" role=\"status\" className=\"mt-1 text-xs text-slate-600\">\n        {message}\n      </p>\n      {open && !loading && results.length > 0 && (\n        <ul id=\"city-list\" role=\"listbox\" aria-label=\"Cities\" className=\"absolute z-20 mt-1 max-h-52 w-full overflow-auto rounded-lg border border-slate-200 bg-white py-1 shadow-lg\">\n          {results.map((c, i) => (\n            <li\n              key={c}\n              id={`city-${i}`}\n              role=\"option\"\n              aria-selected={i === active}\n              onMouseDown={(e) => e.preventDefault()}\n              onClick={() => {\n                setQuery(c);\n                setOpen(false);\n              }}\n              onMouseEnter={() => setActive(i)}\n              className={`flex h-10 cursor-pointer items-center justify-between px-3 text-sm text-slate-800 ${i === active ? \"bg-sky-50\" : \"\"}`}\n            >\n              <span>{c.split(\",\")[0]}</span>\n              <span className=\"text-xs text-slate-500\">{c.split(\", \")[1]}</span>\n            </li>\n          ))}\n        </ul>\n      )}\n    </div>\n  );\n}\n  return AsyncCombobox;\n})();\nconst r5React = \"import { useEffect, useState, type KeyboardEvent } from \\\"react\\\";\\n\\nconst CITIES = [\\\"Lisbon, Portugal\\\", \\\"Lima, Peru\\\", \\\"Lille, France\\\", \\\"Lyon, France\\\", \\\"Leeds, United Kingdom\\\", \\\"Linz, Austria\\\", \\\"Ljubljana, Slovenia\\\", \\\"Lagos, Nigeria\\\", \\\"Oslo, Norway\\\", \\\"Osaka, Japan\\\"];\\n\\n// Stand-in for a network call. Replace the body with your own request and keep the abort signal.\\nfunction searchCities(q: string, signal: AbortSignal): Promise<string[]> {\\n  return new Promise((resolve, reject) => {\\n    const id = setTimeout(() => resolve(CITIES.filter((c) => c.toLowerCase().startsWith(q.toLowerCase()))), 500);\\n    signal.addEventListener(\\\"abort\\\", () => {\\n      clearTimeout(id);\\n      reject(new DOMException(\\\"aborted\\\", \\\"AbortError\\\"));\\n    });\\n  });\\n}\\n\\nexport default function AsyncCombobox() {\\n  const [query, setQuery] = useState(\\\"li\\\");\\n  const [results, setResults] = useState<string[]>([]);\\n  const [loading, setLoading] = useState(false);\\n  const [open, setOpen] = useState(true);\\n  const [active, setActive] = useState(0);\\n\\n  // Debounce 250ms, cancel the previous request, then load.\\n  useEffect(() => {\\n    if (query.trim().length < 2) {\\n      setResults([]);\\n      setLoading(false);\\n      return;\\n    }\\n    const ac = new AbortController();\\n    setLoading(true);\\n    const t = setTimeout(() => {\\n      searchCities(query.trim(), ac.signal)\\n        .then((r) => {\\n          setResults(r);\\n          setActive(0);\\n          setLoading(false);\\n        })\\n        .catch(() => {});\\n    }, 250);\\n    return () => {\\n      clearTimeout(t);\\n      ac.abort();\\n    };\\n  }, [query]);\\n\\n  function onKeyDown(e: KeyboardEvent<HTMLInputElement>) {\\n    if (e.key === \\\"ArrowDown\\\") (open ? setActive(Math.min(results.length - 1, active + 1)) : setOpen(true));\\n    else if (e.key === \\\"ArrowUp\\\") setActive(Math.max(0, active - 1));\\n    else if (e.key === \\\"Enter\\\" && open && results[active]) {\\n      setQuery(results[active]);\\n      setOpen(false);\\n    } else if (e.key === \\\"Escape\\\") setOpen(false);\\n    else return;\\n    e.preventDefault();\\n  }\\n\\n  const message = query.trim().length < 2 ? \\\"Type at least 2 letters\\\" : loading ? \\\"Searching\\\" : results.length ? `${results.length} cities found` : \\\"No cities match\\\";\\n\\n  return (\\n    <div className=\\\"relative w-full max-w-[16rem]\\\" onBlur={(e) => !e.currentTarget.contains(e.relatedTarget) && setOpen(false)}>\\n      <label htmlFor=\\\"city\\\" className=\\\"block text-sm font-semibold text-slate-900\\\">\\n        Office city\\n      </label>\\n      <div className=\\\"relative mt-2\\\">\\n        <input\\n          id=\\\"city\\\"\\n          type=\\\"text\\\"\\n          role=\\\"combobox\\\"\\n          autoComplete=\\\"off\\\"\\n          aria-autocomplete=\\\"list\\\"\\n          aria-expanded={open}\\n          aria-controls=\\\"city-list\\\"\\n          aria-activedescendant={open && !loading && results[active] ? `city-${active}` : undefined}\\n          aria-describedby=\\\"city-status\\\"\\n          value={query}\\n          onChange={(e) => {\\n            setQuery(e.target.value);\\n            setOpen(true);\\n          }}\\n          onFocus={() => setOpen(true)}\\n          onKeyDown={onKeyDown}\\n          className=\\\"h-11 w-full rounded-lg border border-slate-300 bg-white px-3 pr-9 text-base text-slate-900 focus:border-sky-600 focus:outline-none focus:ring-2 focus:ring-sky-600/30 sm:text-sm\\\"\\n        />\\n        {loading && <span aria-hidden=\\\"true\\\" className=\\\"absolute right-3 top-1/2 h-4 w-4 -translate-y-1/2 animate-spin rounded-full border-2 border-slate-300 border-t-sky-600 motion-reduce:animate-none\\\" />}\\n      </div>\\n      <p id=\\\"city-status\\\" role=\\\"status\\\" className=\\\"mt-1 text-xs text-slate-600\\\">\\n        {message}\\n      </p>\\n      {open && !loading && results.length > 0 && (\\n        <ul id=\\\"city-list\\\" role=\\\"listbox\\\" aria-label=\\\"Cities\\\" className=\\\"absolute z-20 mt-1 max-h-52 w-full overflow-auto rounded-lg border border-slate-200 bg-white py-1 shadow-lg\\\">\\n          {results.map((c, i) => (\\n            <li\\n              key={c}\\n              id={`city-${i}`}\\n              role=\\\"option\\\"\\n              aria-selected={i === active}\\n              onMouseDown={(e) => e.preventDefault()}\\n              onClick={() => {\\n                setQuery(c);\\n                setOpen(false);\\n              }}\\n              onMouseEnter={() => setActive(i)}\\n              className={`flex h-10 cursor-pointer items-center justify-between px-3 text-sm text-slate-800 ${i === active ? \\\"bg-sky-50\\\" : \\\"\\\"}`}\\n            >\\n              <span>{c.split(\\\",\\\")[0]}</span>\\n              <span className=\\\"text-xs text-slate-500\\\">{c.split(\\\", \\\")[1]}</span>\\n            </li>\\n          ))}\\n        </ul>\\n      )}\\n    </div>\\n  );\\n}\\n\";\n\nconst r6Demo = (() => {\nconst GROUPS = [\n  { label: \"Americas\", zones: [{ name: \"Pacific Time\", cities: \"Vancouver, Los Angeles\" }, { name: \"Eastern Time\", cities: \"Toronto, New York\" }, { name: \"Brasília Time\", cities: \"São Paulo\" }] },\n  { label: \"Europe\", zones: [{ name: \"Greenwich Mean Time\", cities: \"London, Dublin\" }, { name: \"Central European Time\", cities: \"Berlin, Madrid\" }] },\n  { label: \"Asia Pacific\", zones: [{ name: \"India Standard Time\", cities: \"Mumbai, Bengaluru\" }, { name: \"Japan Standard Time\", cities: \"Tokyo\" }, { name: \"Australian Eastern Time\", cities: \"Sydney\" }] },\n];\nconst FLAT = GROUPS.flatMap((g) => g.zones);\n\n// Grouped listbox: each group is role=\"group\" labelled by its heading.\nfunction GroupedSelect() {\n  const [value, setValue] = useState(4);\n  const [open, setOpen] = useState(false);\n  const [active, setActive] = useState(4);\n  const rootRef = useRef<HTMLDivElement>(null);\n  const listRef = useRef<HTMLDivElement>(null);\n\n  useEffect(() => {\n    if (!open) return;\n    const close = (e: MouseEvent) => !rootRef.current?.contains(e.target as Node) && setOpen(false);\n    document.addEventListener(\"mousedown\", close);\n    return () => document.removeEventListener(\"mousedown\", close);\n  }, [open]);\n\n  useEffect(() => {\n    const list = listRef.current;\n    const el = list?.querySelector<HTMLElement>(`[data-i=\"${active}\"]`);\n    if (!list || !el) return;\n    if (el.offsetTop < list.scrollTop + 28) list.scrollTop = Math.max(0, el.offsetTop - 28);\n    else if (el.offsetTop + el.offsetHeight > list.scrollTop + list.clientHeight) list.scrollTop = el.offsetTop + el.offsetHeight - list.clientHeight;\n  }, [active, open]);\n\n  function choose(i: number) {\n    setValue(i);\n    setOpen(false);\n  }\n\n  function onKeyDown(e: KeyboardEvent<HTMLDivElement>) {\n    const last = FLAT.length - 1;\n    if (!open) {\n      if ([\"ArrowDown\", \"ArrowUp\", \"Enter\", \" \"].includes(e.key)) {\n        e.preventDefault();\n        setActive(value);\n        setOpen(true);\n      }\n      return;\n    }\n    if (e.key === \"ArrowDown\") setActive(Math.min(last, active + 1));\n    else if (e.key === \"ArrowUp\") setActive(Math.max(0, active - 1));\n    else if (e.key === \"Home\") setActive(0);\n    else if (e.key === \"End\") setActive(last);\n    else if (e.key === \"Enter\" || e.key === \" \") choose(active);\n    else if (e.key === \"Escape\") setOpen(false);\n    else if (e.key === \"Tab\") return setOpen(false);\n    else return;\n    e.preventDefault();\n  }\n\n  let n = -1;\n  return (\n    <div ref={rootRef} className=\"relative w-full max-w-[16rem]\">\n      <span id=\"tz-label\" className=\"block text-sm font-semibold text-slate-900\">\n        Time zone\n      </span>\n      <div\n        role=\"combobox\"\n        tabIndex={0}\n        aria-labelledby=\"tz-label\"\n        aria-haspopup=\"listbox\"\n        aria-expanded={open}\n        aria-controls=\"tz-list\"\n        aria-activedescendant={open ? `tz-${active}` : undefined}\n        onClick={() => (open ? setOpen(false) : (setActive(value), setOpen(true)))}\n        onKeyDown={onKeyDown}\n        className=\"mt-2 flex h-12 cursor-pointer flex-col justify-center rounded-lg border border-slate-300 bg-white px-3 focus-visible:border-sky-600 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-sky-600/30\"\n      >\n        <span className=\"text-sm leading-tight text-slate-900\">{FLAT[value].name}</span>\n        <span className=\"text-xs leading-tight text-slate-500\">{FLAT[value].cities}</span>\n      </div>\n      {open && (\n        <div ref={listRef} id=\"tz-list\" role=\"listbox\" aria-labelledby=\"tz-label\" className=\"absolute z-20 mt-1 max-h-56 w-full overflow-auto rounded-lg border border-slate-200 bg-white pb-1 shadow-lg\">\n          {GROUPS.map((g, gi) => (\n            <ul key={g.label} role=\"group\" aria-labelledby={`tz-g-${gi}`}>\n              <li role=\"presentation\" id={`tz-g-${gi}`} className=\"sticky top-0 bg-slate-50 px-3 py-1.5 text-[11px] font-semibold uppercase tracking-wider text-slate-600\">\n                {g.label}\n              </li>\n              {g.zones.map((z) => {\n                n += 1;\n                const i = n;\n                return (\n                  <li\n                    key={z.name}\n                    id={`tz-${i}`}\n                    data-i={i}\n                    role=\"option\"\n                    aria-selected={i === value}\n                    onMouseDown={(e) => e.preventDefault()}\n                    onClick={() => choose(i)}\n                    onMouseEnter={() => setActive(i)}\n                    className={`cursor-pointer px-3 py-2 ${i === active ? \"bg-sky-50\" : \"\"}`}\n                  >\n                    <span className={`block text-sm ${i === value ? \"font-semibold text-sky-900\" : \"text-slate-800\"}`}>{z.name}</span>\n                    <span className=\"block text-xs text-slate-500\">{z.cities}</span>\n                  </li>\n                );\n              })}\n            </ul>\n          ))}\n        </div>\n      )}\n    </div>\n  );\n}\n  return GroupedSelect;\n})();\nconst r6React = \"import { useEffect, useRef, useState, type KeyboardEvent } from \\\"react\\\";\\n\\nconst GROUPS = [\\n  { label: \\\"Americas\\\", zones: [{ name: \\\"Pacific Time\\\", cities: \\\"Vancouver, Los Angeles\\\" }, { name: \\\"Eastern Time\\\", cities: \\\"Toronto, New York\\\" }, { name: \\\"Brasília Time\\\", cities: \\\"São Paulo\\\" }] },\\n  { label: \\\"Europe\\\", zones: [{ name: \\\"Greenwich Mean Time\\\", cities: \\\"London, Dublin\\\" }, { name: \\\"Central European Time\\\", cities: \\\"Berlin, Madrid\\\" }] },\\n  { label: \\\"Asia Pacific\\\", zones: [{ name: \\\"India Standard Time\\\", cities: \\\"Mumbai, Bengaluru\\\" }, { name: \\\"Japan Standard Time\\\", cities: \\\"Tokyo\\\" }, { name: \\\"Australian Eastern Time\\\", cities: \\\"Sydney\\\" }] },\\n];\\nconst FLAT = GROUPS.flatMap((g) => g.zones);\\n\\n// Grouped listbox: each group is role=\\\"group\\\" labelled by its heading.\\nexport default function GroupedSelect() {\\n  const [value, setValue] = useState(4);\\n  const [open, setOpen] = useState(false);\\n  const [active, setActive] = useState(4);\\n  const rootRef = useRef<HTMLDivElement>(null);\\n  const listRef = useRef<HTMLDivElement>(null);\\n\\n  useEffect(() => {\\n    if (!open) return;\\n    const close = (e: MouseEvent) => !rootRef.current?.contains(e.target as Node) && setOpen(false);\\n    document.addEventListener(\\\"mousedown\\\", close);\\n    return () => document.removeEventListener(\\\"mousedown\\\", close);\\n  }, [open]);\\n\\n  useEffect(() => {\\n    const list = listRef.current;\\n    const el = list?.querySelector<HTMLElement>(`[data-i=\\\"${active}\\\"]`);\\n    if (!list || !el) return;\\n    if (el.offsetTop < list.scrollTop + 28) list.scrollTop = Math.max(0, el.offsetTop - 28);\\n    else if (el.offsetTop + el.offsetHeight > list.scrollTop + list.clientHeight) list.scrollTop = el.offsetTop + el.offsetHeight - list.clientHeight;\\n  }, [active, open]);\\n\\n  function choose(i: number) {\\n    setValue(i);\\n    setOpen(false);\\n  }\\n\\n  function onKeyDown(e: KeyboardEvent<HTMLDivElement>) {\\n    const last = FLAT.length - 1;\\n    if (!open) {\\n      if ([\\\"ArrowDown\\\", \\\"ArrowUp\\\", \\\"Enter\\\", \\\" \\\"].includes(e.key)) {\\n        e.preventDefault();\\n        setActive(value);\\n        setOpen(true);\\n      }\\n      return;\\n    }\\n    if (e.key === \\\"ArrowDown\\\") setActive(Math.min(last, active + 1));\\n    else if (e.key === \\\"ArrowUp\\\") setActive(Math.max(0, active - 1));\\n    else if (e.key === \\\"Home\\\") setActive(0);\\n    else if (e.key === \\\"End\\\") setActive(last);\\n    else if (e.key === \\\"Enter\\\" || e.key === \\\" \\\") choose(active);\\n    else if (e.key === \\\"Escape\\\") setOpen(false);\\n    else if (e.key === \\\"Tab\\\") return setOpen(false);\\n    else return;\\n    e.preventDefault();\\n  }\\n\\n  let n = -1;\\n  return (\\n    <div ref={rootRef} className=\\\"relative w-full max-w-[16rem]\\\">\\n      <span id=\\\"tz-label\\\" className=\\\"block text-sm font-semibold text-slate-900\\\">\\n        Time zone\\n      </span>\\n      <div\\n        role=\\\"combobox\\\"\\n        tabIndex={0}\\n        aria-labelledby=\\\"tz-label\\\"\\n        aria-haspopup=\\\"listbox\\\"\\n        aria-expanded={open}\\n        aria-controls=\\\"tz-list\\\"\\n        aria-activedescendant={open ? `tz-${active}` : undefined}\\n        onClick={() => (open ? setOpen(false) : (setActive(value), setOpen(true)))}\\n        onKeyDown={onKeyDown}\\n        className=\\\"mt-2 flex h-12 cursor-pointer flex-col justify-center rounded-lg border border-slate-300 bg-white px-3 focus-visible:border-sky-600 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-sky-600/30\\\"\\n      >\\n        <span className=\\\"text-sm leading-tight text-slate-900\\\">{FLAT[value].name}</span>\\n        <span className=\\\"text-xs leading-tight text-slate-500\\\">{FLAT[value].cities}</span>\\n      </div>\\n      {open && (\\n        <div ref={listRef} id=\\\"tz-list\\\" role=\\\"listbox\\\" aria-labelledby=\\\"tz-label\\\" className=\\\"absolute z-20 mt-1 max-h-56 w-full overflow-auto rounded-lg border border-slate-200 bg-white pb-1 shadow-lg\\\">\\n          {GROUPS.map((g, gi) => (\\n            <ul key={g.label} role=\\\"group\\\" aria-labelledby={`tz-g-${gi}`}>\\n              <li role=\\\"presentation\\\" id={`tz-g-${gi}`} className=\\\"sticky top-0 bg-slate-50 px-3 py-1.5 text-[11px] font-semibold uppercase tracking-wider text-slate-600\\\">\\n                {g.label}\\n              </li>\\n              {g.zones.map((z) => {\\n                n += 1;\\n                const i = n;\\n                return (\\n                  <li\\n                    key={z.name}\\n                    id={`tz-${i}`}\\n                    data-i={i}\\n                    role=\\\"option\\\"\\n                    aria-selected={i === value}\\n                    onMouseDown={(e) => e.preventDefault()}\\n                    onClick={() => choose(i)}\\n                    onMouseEnter={() => setActive(i)}\\n                    className={`cursor-pointer px-3 py-2 ${i === active ? \\\"bg-sky-50\\\" : \\\"\\\"}`}\\n                  >\\n                    <span className={`block text-sm ${i === value ? \\\"font-semibold text-sky-900\\\" : \\\"text-slate-800\\\"}`}>{z.name}</span>\\n                    <span className=\\\"block text-xs text-slate-500\\\">{z.cities}</span>\\n                  </li>\\n                );\\n              })}\\n            </ul>\\n          ))}\\n        </div>\\n      )}\\n    </div>\\n  );\\n}\\n\";\n\nconst r3Demo = (() => {\nconst TEAMS = [\"Design\", \"Engineering\", \"Marketing\", \"Operations\", \"Sales\", \"Support\"];\n\n// Select-only combobox whose listbox allows several choices (aria-multiselectable).\nfunction MultiSelectCheckmarks() {\n  const [picked, setPicked] = useState<string[]>([\"Design\", \"Marketing\"]);\n  const [open, setOpen] = useState(false);\n  const [active, setActive] = useState(0);\n  const rootRef = useRef<HTMLDivElement>(null);\n\n  useEffect(() => {\n    if (!open) return;\n    const close = (e: MouseEvent) => !rootRef.current?.contains(e.target as Node) && setOpen(false);\n    document.addEventListener(\"mousedown\", close);\n    return () => document.removeEventListener(\"mousedown\", close);\n  }, [open]);\n\n  const toggle = (t: string) => setPicked(picked.includes(t) ? picked.filter((p) => p !== t) : [...picked, t]);\n\n  function onKeyDown(e: KeyboardEvent<HTMLDivElement>) {\n    if (!open) {\n      if ([\"ArrowDown\", \"Enter\", \" \"].includes(e.key)) {\n        e.preventDefault();\n        setOpen(true);\n      }\n      return;\n    }\n    if (e.key === \"ArrowDown\") setActive(Math.min(TEAMS.length - 1, active + 1));\n    else if (e.key === \"ArrowUp\") setActive(Math.max(0, active - 1));\n    else if (e.key === \"Enter\" || e.key === \" \") toggle(TEAMS[active]);\n    else if (e.key === \"Escape\") setOpen(false);\n    else if (e.key === \"Tab\") return setOpen(false);\n    else return;\n    e.preventDefault();\n  }\n\n  const summary = picked.length === 0 ? \"Any team\" : picked.length <= 2 ? picked.join(\", \") : `${picked[0]}, ${picked[1]} +${picked.length - 2}`;\n\n  return (\n    <div ref={rootRef} className=\"relative w-full max-w-[16rem]\">\n      <div className=\"flex items-center justify-between\">\n        <span id=\"teams-label\" className=\"text-sm font-semibold text-slate-900\">\n          Visible to teams\n        </span>\n        {picked.length > 0 && (\n          <button type=\"button\" onClick={() => setPicked([])} className=\"h-10 rounded-md px-2 text-xs font-medium text-sky-800 hover:bg-sky-50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-sky-600\">\n            Clear\n          </button>\n        )}\n      </div>\n      <div\n        role=\"combobox\"\n        tabIndex={0}\n        aria-labelledby=\"teams-label\"\n        aria-haspopup=\"listbox\"\n        aria-expanded={open}\n        aria-controls=\"teams-list\"\n        aria-activedescendant={open ? `team-${active}` : undefined}\n        onClick={() => setOpen(!open)}\n        onKeyDown={onKeyDown}\n        className=\"flex h-11 cursor-pointer items-center gap-2 rounded-lg border border-slate-300 bg-white px-3 text-sm text-slate-900 focus-visible:border-sky-600 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-sky-600/30\"\n      >\n        <span className=\"flex-1 truncate\">{summary}</span>\n        <span className=\"rounded bg-slate-100 px-1.5 text-xs tabular-nums text-slate-700\">{picked.length}</span>\n      </div>\n      {open && (\n        <ul id=\"teams-list\" role=\"listbox\" aria-multiselectable=\"true\" aria-labelledby=\"teams-label\" className=\"absolute z-20 mt-1 w-full rounded-lg border border-slate-200 bg-white py-1 shadow-lg\">\n          {TEAMS.map((t, i) => {\n            const on = picked.includes(t);\n            return (\n              <li\n                key={t}\n                id={`team-${i}`}\n                role=\"option\"\n                aria-selected={on}\n                onMouseDown={(e) => e.preventDefault()}\n                onClick={() => toggle(t)}\n                onMouseEnter={() => setActive(i)}\n                className={`flex h-10 cursor-pointer items-center gap-2.5 px-3 text-sm text-slate-800 ${i === active ? \"bg-sky-50\" : \"\"}`}\n              >\n                <span aria-hidden=\"true\" className={`grid h-4 w-4 place-items-center rounded border ${on ? \"border-sky-700 bg-sky-700\" : \"border-slate-400 bg-white\"}`}>\n                  {on && (\n                    <svg viewBox=\"0 0 20 20\" className=\"h-3 w-3 fill-none stroke-white\" strokeWidth={3} strokeLinecap=\"round\" strokeLinejoin=\"round\">\n                      <path d=\"M5 10.5l3.5 3.5L15 7\" />\n                    </svg>\n                  )}\n                </span>\n                {t}\n              </li>\n            );\n          })}\n        </ul>\n      )}\n    </div>\n  );\n}\n  return MultiSelectCheckmarks;\n})();\nconst r3React = \"import { useEffect, useRef, useState, type KeyboardEvent } from \\\"react\\\";\\n\\nconst TEAMS = [\\\"Design\\\", \\\"Engineering\\\", \\\"Marketing\\\", \\\"Operations\\\", \\\"Sales\\\", \\\"Support\\\"];\\n\\n// Select-only combobox whose listbox allows several choices (aria-multiselectable).\\nexport default function MultiSelectCheckmarks() {\\n  const [picked, setPicked] = useState<string[]>([\\\"Design\\\", \\\"Marketing\\\"]);\\n  const [open, setOpen] = useState(false);\\n  const [active, setActive] = useState(0);\\n  const rootRef = useRef<HTMLDivElement>(null);\\n\\n  useEffect(() => {\\n    if (!open) return;\\n    const close = (e: MouseEvent) => !rootRef.current?.contains(e.target as Node) && setOpen(false);\\n    document.addEventListener(\\\"mousedown\\\", close);\\n    return () => document.removeEventListener(\\\"mousedown\\\", close);\\n  }, [open]);\\n\\n  const toggle = (t: string) => setPicked(picked.includes(t) ? picked.filter((p) => p !== t) : [...picked, t]);\\n\\n  function onKeyDown(e: KeyboardEvent<HTMLDivElement>) {\\n    if (!open) {\\n      if ([\\\"ArrowDown\\\", \\\"Enter\\\", \\\" \\\"].includes(e.key)) {\\n        e.preventDefault();\\n        setOpen(true);\\n      }\\n      return;\\n    }\\n    if (e.key === \\\"ArrowDown\\\") setActive(Math.min(TEAMS.length - 1, active + 1));\\n    else if (e.key === \\\"ArrowUp\\\") setActive(Math.max(0, active - 1));\\n    else if (e.key === \\\"Enter\\\" || e.key === \\\" \\\") toggle(TEAMS[active]);\\n    else if (e.key === \\\"Escape\\\") setOpen(false);\\n    else if (e.key === \\\"Tab\\\") return setOpen(false);\\n    else return;\\n    e.preventDefault();\\n  }\\n\\n  const summary = picked.length === 0 ? \\\"Any team\\\" : picked.length <= 2 ? picked.join(\\\", \\\") : `${picked[0]}, ${picked[1]} +${picked.length - 2}`;\\n\\n  return (\\n    <div ref={rootRef} className=\\\"relative w-full max-w-[16rem]\\\">\\n      <div className=\\\"flex items-center justify-between\\\">\\n        <span id=\\\"teams-label\\\" className=\\\"text-sm font-semibold text-slate-900\\\">\\n          Visible to teams\\n        </span>\\n        {picked.length > 0 && (\\n          <button type=\\\"button\\\" onClick={() => setPicked([])} className=\\\"h-10 rounded-md px-2 text-xs font-medium text-sky-800 hover:bg-sky-50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-sky-600\\\">\\n            Clear\\n          </button>\\n        )}\\n      </div>\\n      <div\\n        role=\\\"combobox\\\"\\n        tabIndex={0}\\n        aria-labelledby=\\\"teams-label\\\"\\n        aria-haspopup=\\\"listbox\\\"\\n        aria-expanded={open}\\n        aria-controls=\\\"teams-list\\\"\\n        aria-activedescendant={open ? `team-${active}` : undefined}\\n        onClick={() => setOpen(!open)}\\n        onKeyDown={onKeyDown}\\n        className=\\\"flex h-11 cursor-pointer items-center gap-2 rounded-lg border border-slate-300 bg-white px-3 text-sm text-slate-900 focus-visible:border-sky-600 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-sky-600/30\\\"\\n      >\\n        <span className=\\\"flex-1 truncate\\\">{summary}</span>\\n        <span className=\\\"rounded bg-slate-100 px-1.5 text-xs tabular-nums text-slate-700\\\">{picked.length}</span>\\n      </div>\\n      {open && (\\n        <ul id=\\\"teams-list\\\" role=\\\"listbox\\\" aria-multiselectable=\\\"true\\\" aria-labelledby=\\\"teams-label\\\" className=\\\"absolute z-20 mt-1 w-full rounded-lg border border-slate-200 bg-white py-1 shadow-lg\\\">\\n          {TEAMS.map((t, i) => {\\n            const on = picked.includes(t);\\n            return (\\n              <li\\n                key={t}\\n                id={`team-${i}`}\\n                role=\\\"option\\\"\\n                aria-selected={on}\\n                onMouseDown={(e) => e.preventDefault()}\\n                onClick={() => toggle(t)}\\n                onMouseEnter={() => setActive(i)}\\n                className={`flex h-10 cursor-pointer items-center gap-2.5 px-3 text-sm text-slate-800 ${i === active ? \\\"bg-sky-50\\\" : \\\"\\\"}`}\\n              >\\n                <span aria-hidden=\\\"true\\\" className={`grid h-4 w-4 place-items-center rounded border ${on ? \\\"border-sky-700 bg-sky-700\\\" : \\\"border-slate-400 bg-white\\\"}`}>\\n                  {on && (\\n                    <svg viewBox=\\\"0 0 20 20\\\" className=\\\"h-3 w-3 fill-none stroke-white\\\" strokeWidth={3} strokeLinecap=\\\"round\\\" strokeLinejoin=\\\"round\\\">\\n                      <path d=\\\"M5 10.5l3.5 3.5L15 7\\\" />\\n                    </svg>\\n                  )}\\n                </span>\\n                {t}\\n              </li>\\n            );\\n          })}\\n        </ul>\\n      )}\\n    </div>\\n  );\\n}\\n\";\n\nconst r4Demo = (() => {\nconst TOOLS = [\"Figma\", \"Framer\", \"Notion\", \"Linear\", \"GitHub\", \"Slack\", \"Webflow\", \"Airtable\", \"Miro\"];\n\n// Multi-select with chips and a search box. Only known options can be added.\nfunction TagMultiSelect() {\n  const [tags, setTags] = useState<string[]>([\"Figma\", \"Notion\"]);\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 options = TOOLS.filter((t) => !tags.includes(t) && t.toLowerCase().includes(query.toLowerCase()));\n\n  function add(t: string) {\n    setTags([...tags, t]);\n    setQuery(\"\");\n    setActive(0);\n    inputRef.current?.focus();\n  }\n\n  function remove(t: string) {\n    setTags(tags.filter((x) => x !== t));\n    inputRef.current?.focus();\n  }\n\n  function onKeyDown(e: KeyboardEvent<HTMLInputElement>) {\n    if (e.key === \"ArrowDown\") {\n      setOpen(true);\n      setActive(Math.min(options.length - 1, active + 1));\n    } else if (e.key === \"ArrowUp\") setActive(Math.max(0, active - 1));\n    else if (e.key === \"Enter\" && open && options[active]) add(options[active]);\n    else if (e.key === \"Escape\") setOpen(false);\n    else if (e.key === \"Backspace\" && !query && tags.length) return setTags(tags.slice(0, -1));\n    else return;\n    e.preventDefault();\n  }\n\n  return (\n    <div className=\"relative w-full max-w-[17rem]\" onBlur={(e) => !e.currentTarget.contains(e.relatedTarget) && setOpen(false)}>\n      <label htmlFor=\"tools-input\" className=\"block text-sm font-semibold text-slate-900\">\n        Tools you use\n      </label>\n      <div className=\"mt-2 flex min-h-[44px] flex-wrap items-center gap-1.5 rounded-lg border border-slate-300 bg-white p-1.5 focus-within:border-sky-600 focus-within:ring-2 focus-within:ring-sky-600/30\">\n        <ul aria-label=\"Selected tools\" className=\"contents\">\n          {tags.map((t) => (\n            <li key={t} className=\"flex h-8 items-center gap-1 rounded-md bg-sky-50 pl-2 text-sm text-sky-900 ring-1 ring-inset ring-sky-200\">\n              {t}\n              <button type=\"button\" aria-label={`Remove ${t}`} onClick={() => remove(t)} className=\"grid h-8 w-7 place-items-center rounded-md text-sky-800 hover:bg-sky-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-sky-600\">\n                <svg viewBox=\"0 0 20 20\" aria-hidden=\"true\" className=\"h-3 w-3 fill-none stroke-current\" strokeWidth={2.4} strokeLinecap=\"round\">\n                  <path d=\"M6 6l8 8M14 6l-8 8\" />\n                </svg>\n              </button>\n            </li>\n          ))}\n        </ul>\n        <input\n          ref={inputRef}\n          id=\"tools-input\"\n          type=\"text\"\n          role=\"combobox\"\n          autoComplete=\"off\"\n          aria-autocomplete=\"list\"\n          aria-expanded={open}\n          aria-controls=\"tools-list\"\n          aria-activedescendant={open && options[active] ? `tool-${active}` : undefined}\n          value={query}\n          placeholder={tags.length ? \"Add more\" : \"Search tools\"}\n          onChange={(e) => {\n            setQuery(e.target.value);\n            setActive(0);\n            setOpen(true);\n          }}\n          onFocus={() => setOpen(true)}\n          onKeyDown={onKeyDown}\n          className=\"h-8 min-w-[6rem] flex-1 bg-transparent px-1 text-base text-slate-900 outline-none placeholder:text-slate-500 sm:text-sm\"\n        />\n      </div>\n      {open && (\n        <ul id=\"tools-list\" role=\"listbox\" aria-label=\"Tools\" className=\"absolute z-20 mt-1 max-h-48 w-full overflow-auto rounded-lg border border-slate-200 bg-white py-1 shadow-lg\">\n          {options.map((t, i) => (\n            <li\n              key={t}\n              id={`tool-${i}`}\n              role=\"option\"\n              aria-selected={false}\n              onMouseDown={(e) => e.preventDefault()}\n              onClick={() => add(t)}\n              onMouseEnter={() => setActive(i)}\n              className={`flex h-10 cursor-pointer items-center px-3 text-sm text-slate-800 ${i === active ? \"bg-sky-50\" : \"\"}`}\n            >\n              {t}\n            </li>\n          ))}\n          {options.length === 0 && <li className=\"px-3 py-2 text-sm text-slate-600\">Nothing left to add</li>}\n        </ul>\n      )}\n      <p className=\"mt-2 text-xs text-slate-600\">Backspace in the empty box removes the last tool.</p>\n    </div>\n  );\n}\n  return TagMultiSelect;\n})();\nconst r4React = \"import { useRef, useState, type KeyboardEvent } from \\\"react\\\";\\n\\nconst TOOLS = [\\\"Figma\\\", \\\"Framer\\\", \\\"Notion\\\", \\\"Linear\\\", \\\"GitHub\\\", \\\"Slack\\\", \\\"Webflow\\\", \\\"Airtable\\\", \\\"Miro\\\"];\\n\\n// Multi-select with chips and a search box. Only known options can be added.\\nexport default function TagMultiSelect() {\\n  const [tags, setTags] = useState<string[]>([\\\"Figma\\\", \\\"Notion\\\"]);\\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 options = TOOLS.filter((t) => !tags.includes(t) && t.toLowerCase().includes(query.toLowerCase()));\\n\\n  function add(t: string) {\\n    setTags([...tags, t]);\\n    setQuery(\\\"\\\");\\n    setActive(0);\\n    inputRef.current?.focus();\\n  }\\n\\n  function remove(t: string) {\\n    setTags(tags.filter((x) => x !== t));\\n    inputRef.current?.focus();\\n  }\\n\\n  function onKeyDown(e: KeyboardEvent<HTMLInputElement>) {\\n    if (e.key === \\\"ArrowDown\\\") {\\n      setOpen(true);\\n      setActive(Math.min(options.length - 1, active + 1));\\n    } else if (e.key === \\\"ArrowUp\\\") setActive(Math.max(0, active - 1));\\n    else if (e.key === \\\"Enter\\\" && open && options[active]) add(options[active]);\\n    else if (e.key === \\\"Escape\\\") setOpen(false);\\n    else if (e.key === \\\"Backspace\\\" && !query && tags.length) return setTags(tags.slice(0, -1));\\n    else return;\\n    e.preventDefault();\\n  }\\n\\n  return (\\n    <div className=\\\"relative w-full max-w-[17rem]\\\" onBlur={(e) => !e.currentTarget.contains(e.relatedTarget) && setOpen(false)}>\\n      <label htmlFor=\\\"tools-input\\\" className=\\\"block text-sm font-semibold text-slate-900\\\">\\n        Tools you use\\n      </label>\\n      <div className=\\\"mt-2 flex min-h-[44px] flex-wrap items-center gap-1.5 rounded-lg border border-slate-300 bg-white p-1.5 focus-within:border-sky-600 focus-within:ring-2 focus-within:ring-sky-600/30\\\">\\n        <ul aria-label=\\\"Selected tools\\\" className=\\\"contents\\\">\\n          {tags.map((t) => (\\n            <li key={t} className=\\\"flex h-8 items-center gap-1 rounded-md bg-sky-50 pl-2 text-sm text-sky-900 ring-1 ring-inset ring-sky-200\\\">\\n              {t}\\n              <button type=\\\"button\\\" aria-label={`Remove ${t}`} onClick={() => remove(t)} className=\\\"grid h-8 w-7 place-items-center rounded-md text-sky-800 hover:bg-sky-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-sky-600\\\">\\n                <svg viewBox=\\\"0 0 20 20\\\" aria-hidden=\\\"true\\\" className=\\\"h-3 w-3 fill-none stroke-current\\\" strokeWidth={2.4} strokeLinecap=\\\"round\\\">\\n                  <path d=\\\"M6 6l8 8M14 6l-8 8\\\" />\\n                </svg>\\n              </button>\\n            </li>\\n          ))}\\n        </ul>\\n        <input\\n          ref={inputRef}\\n          id=\\\"tools-input\\\"\\n          type=\\\"text\\\"\\n          role=\\\"combobox\\\"\\n          autoComplete=\\\"off\\\"\\n          aria-autocomplete=\\\"list\\\"\\n          aria-expanded={open}\\n          aria-controls=\\\"tools-list\\\"\\n          aria-activedescendant={open && options[active] ? `tool-${active}` : undefined}\\n          value={query}\\n          placeholder={tags.length ? \\\"Add more\\\" : \\\"Search tools\\\"}\\n          onChange={(e) => {\\n            setQuery(e.target.value);\\n            setActive(0);\\n            setOpen(true);\\n          }}\\n          onFocus={() => setOpen(true)}\\n          onKeyDown={onKeyDown}\\n          className=\\\"h-8 min-w-[6rem] flex-1 bg-transparent px-1 text-base text-slate-900 outline-none placeholder:text-slate-500 sm:text-sm\\\"\\n        />\\n      </div>\\n      {open && (\\n        <ul id=\\\"tools-list\\\" role=\\\"listbox\\\" aria-label=\\\"Tools\\\" className=\\\"absolute z-20 mt-1 max-h-48 w-full overflow-auto rounded-lg border border-slate-200 bg-white py-1 shadow-lg\\\">\\n          {options.map((t, i) => (\\n            <li\\n              key={t}\\n              id={`tool-${i}`}\\n              role=\\\"option\\\"\\n              aria-selected={false}\\n              onMouseDown={(e) => e.preventDefault()}\\n              onClick={() => add(t)}\\n              onMouseEnter={() => setActive(i)}\\n              className={`flex h-10 cursor-pointer items-center px-3 text-sm text-slate-800 ${i === active ? \\\"bg-sky-50\\\" : \\\"\\\"}`}\\n            >\\n              {t}\\n            </li>\\n          ))}\\n          {options.length === 0 && <li className=\\\"px-3 py-2 text-sm text-slate-600\\\">Nothing left to add</li>}\\n        </ul>\\n      )}\\n      <p className=\\\"mt-2 text-xs text-slate-600\\\">Backspace in the empty box removes the last tool.</p>\\n    </div>\\n  );\\n}\\n\";\n\nconst PIECES: Piece[] = [\n  { id: \"r1\", name: \"Select-only dropdown\", blurb: \"A styled replacement for a native select, with status dots and type-ahead.\", group: \"single\", Demo: r1Demo, react: r1React, stage: \"min-h-[320px] bg-slate-50 ring-1 ring-inset ring-slate-200/80\" },\n  { id: \"r2\", name: \"Searchable combobox\", blurb: \"Filters teammates as you type and bolds the matching letters.\", group: \"single\", Demo: r2Demo, react: r2React, stage: \"min-h-[320px] bg-slate-50 ring-1 ring-inset ring-slate-200/80\" },\n  { id: \"r5\", name: \"Async options with debounce\", blurb: \"Waits for a pause, cancels the old request and announces the result count.\", group: \"single\", Demo: r5Demo, react: r5React, stage: \"min-h-[320px] bg-slate-50 ring-1 ring-inset ring-slate-200/80\" },\n  { id: \"r6\", name: \"Grouped options with descriptions\", blurb: \"Time zones in labelled groups with sticky headings.\", group: \"single\", Demo: r6Demo, react: r6React, stage: \"min-h-[320px] bg-slate-50 ring-1 ring-inset ring-slate-200/80\" },\n  { id: \"r3\", name: \"Multi-select with checkmarks\", blurb: \"The list stays open while you toggle, and the field sums up the choice.\", group: \"multi\", Demo: r3Demo, react: r3React, stage: \"min-h-[320px] bg-slate-50 ring-1 ring-inset ring-slate-200/80\" },\n  { id: \"r4\", name: \"Chip multi-select\", blurb: \"Search a fixed list, add chips, remove with a button or Backspace.\", group: \"multi\", Demo: r4Demo, react: r4React, stage: \"min-h-[320px] bg-slate-50 ring-1 ring-inset ring-slate-200/80\" }\n];\nconst GROUPS: { key: string; label: string }[] = [{\"key\":\"single\",\"label\":\"Single select\"},{\"key\":\"multi\",\"label\":\"Multi select\"}];\nconst TEXT: { eyebrow: string; title: string; lead: string; refTitle: string; refNote: string } = {\"eyebrow\":\"React · Tailwind · no dependencies\",\"title\":\"React select and searchable dropdowns\",\"lead\":\"Six dropdowns built on the combobox pattern: a select-only menu with type-ahead, a searchable autocomplete, grouped options, a checkmark multi-select, a chip multi-select and a search that loads results as you type. No package, full keyboard support.\",\"refTitle\":\"Combobox keyboard and ARIA reference\",\"refNote\":\"Roles, states and keys follow the combobox and listbox patterns in the WAI-ARIA Authoring Practices Guide. DOM focus never leaves the combobox; aria-activedescendant tells assistive technology which option is highlighted.\"};\nconst REF_HEAD: string[] = [\"Key or attribute\",\"Behaviour\",\"Pieces\"];\nconst REF_ROWS: string[][] = [\n  [\n    \"Down Arrow / Up Arrow\",\n    \"Open the list if closed, otherwise move the highlight to the next or previous option.\",\n    \"All six.\"\n  ],\n  [\n    \"Enter\",\n    \"Accept the highlighted option and close the list. In the multi-selects it toggles or adds the option instead.\",\n    \"All six.\"\n  ],\n  [\n    \"Escape\",\n    \"Close the list. In the searchable field, a second Escape clears the text.\",\n    \"All six.\"\n  ],\n  [\n    \"Home / End\",\n    \"Highlight the first or last option while the list is open.\",\n    \"Select-only and grouped.\"\n  ],\n  [\n    \"Printable letters\",\n    \"Type-ahead in the select-only menu; filter the options in the editable ones.\",\n    \"Status (type-ahead), assignee, tools, city.\"\n  ],\n  [\n    \"role=\\\"combobox\\\" + aria-expanded\",\n    \"Marks the field that controls a popup list and says whether the list is shown.\",\n    \"All six.\"\n  ],\n  [\n    \"aria-controls + aria-activedescendant\",\n    \"Point from the combobox to the listbox and to the id of the highlighted option.\",\n    \"All six.\"\n  ],\n  [\n    \"aria-autocomplete=\\\"list\\\"\",\n    \"Says the options are filtered by what is typed, without inline completion.\",\n    \"Assignee, tools, city.\"\n  ],\n  [\n    \"aria-multiselectable=\\\"true\\\"\",\n    \"On the listbox, tells users that more than one option can be selected.\",\n    \"Team visibility.\"\n  ]\n];\n\nconst COPY_ICON = \"M9 9h10v10H9zM5 15V5h10\";\nconst CHECK_ICON = \"M5 12.5l4.5 4.5L19 7.5\";\nconst CODE_ICON = \"M8 7l-5 5 5 5M16 7l5 5-5 5\";\n\nexport default function ReactSelectDropdownCollection() {\n  const [group, setGroup] = useState(\"all\");\n  const [langs, setLangs] = useState<Record<string, Lang>>({});\n  const [open, setOpen] = useState<string | null>(null);\n  const [copied, setCopied] = useState<string | null>(null);\n  const [announce, setAnnounce] = useState(\"\");\n  const timer = useRef<ReturnType<typeof setTimeout> | null>(null);\n\n  useEffect(\n    () => () => {\n      if (timer.current) clearTimeout(timer.current);\n    },\n    []\n  );\n\n  const shown = group === \"all\" ? PIECES : PIECES.filter((p) => p.group === group);\n  const langOf = (p: Piece): Lang => (p.html ? langs[p.id] ?? \"react\" : \"react\");\n  const codeOf = (p: Piece) => (langOf(p) === \"html\" && p.html ? p.html : p.react);\n  const langName = (l: Lang) => (l === \"html\" ? \"HTML, CSS and JS\" : \"React and Tailwind\");\n\n  async function copy(p: Piece) {\n    let ok = false;\n    try {\n      await navigator.clipboard.writeText(codeOf(p));\n      ok = true;\n    } catch {\n      ok = false;\n    }\n    if (!ok) setOpen(p.id);\n    setCopied(ok ? p.id : null);\n    setAnnounce(ok ? `${p.name}: ${langName(langOf(p))} copied` : \"Copy was blocked, so the code is shown under the demo for you to select\");\n    if (timer.current) clearTimeout(timer.current);\n    timer.current = setTimeout(() => setCopied(null), 1600);\n  }\n\n  const ring = \"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-sky-600 focus-visible:ring-offset-2\";\n  const chip = `inline-flex min-h-[40px] items-center gap-1.5 whitespace-nowrap rounded-full px-4 text-[13px] font-medium transition-colors ${ring}`;\n\n  return (\n    <section\n      className=\"bg-[#f8fafc] px-4 py-12 sm:px-8 sm:py-14\"\n      style={{ fontFamily: 'Inter, ui-sans-serif, system-ui, -apple-system, \"Segoe UI\", sans-serif' }}\n    >\n      <div className=\"mx-auto max-w-6xl\">\n        <header className=\"max-w-3xl\">\n          <p className=\"font-mono text-[12px] uppercase tracking-[0.18em] text-stone-600\">{TEXT.eyebrow}</p>\n          <h2 className=\"mt-3 text-[32px] font-semibold leading-[1.08] tracking-[-0.03em] text-stone-950 sm:text-[42px]\">{TEXT.title}</h2>\n          <p className=\"mt-4 max-w-2xl text-[15px] leading-relaxed text-stone-600\">{TEXT.lead}</p>\n        </header>\n\n        <div role=\"group\" aria-label=\"Filter the collection\" className=\"mt-8 flex flex-wrap gap-1.5 border-y border-stone-300/70 py-4\">\n          {[{ key: \"all\", label: \"All\" }, ...GROUPS, { key: \"ref\", label: \"Reference table\" }].map((g) => {\n            const on = group === g.key;\n            const n = g.key === \"ref\" ? REF_ROWS.length : g.key === \"all\" ? PIECES.length : PIECES.filter((p) => p.group === g.key).length;\n            return (\n              <button\n                key={g.key}\n                type=\"button\"\n                aria-pressed={on}\n                onClick={() => setGroup(g.key)}\n                className={`${chip} ${on ? \"bg-sky-800 text-white\" : \"bg-white text-stone-700 ring-1 ring-inset ring-stone-300 hover:bg-stone-100\"}`}\n              >\n                {g.label}\n                <span className={`font-mono text-[11px] ${on ? \"opacity-75\" : \"text-stone-500\"}`}>{n}</span>\n              </button>\n            );\n          })}\n        </div>\n\n        <p className=\"sr-only\" aria-live=\"polite\">\n          {announce}\n        </p>\n\n        {group !== \"ref\" && (\n        <ul className=\"mt-6 grid grid-cols-1 items-start gap-4 md:grid-cols-2 lg:grid-cols-3\">\n          {shown.map((p) => {\n            const isOpen = open === p.id;\n            const l = langOf(p);\n            return (\n              <li\n                key={p.id}\n                className={`flex min-w-0 flex-col rounded-2xl border border-stone-200 bg-white shadow-[0_1px_2px_rgba(28,25,23,0.05)] ${isOpen ? \"md:col-span-2 lg:col-span-3\" : \"\"}`}\n              >\n                <div className=\"px-4 pt-4\">\n                  <h3 className=\"text-[14px] font-semibold text-stone-950\">{p.name}</h3>\n                  <p className=\"mt-0.5 text-[13px] leading-snug text-stone-600\">{p.blurb}</p>\n                </div>\n                <div className={`relative mx-3 mt-3 flex min-w-0 items-start justify-center rounded-xl px-3 py-6 sm:px-5 ${p.stage}`}>\n                  <p.Demo />\n                </div>\n                <div className=\"flex flex-wrap items-center gap-2 px-3 py-3\">\n                  {p.html && (\n                    <div role=\"group\" aria-label={`Code version for ${p.name}`} className=\"inline-flex rounded-lg bg-stone-100 p-0.5\">\n                      {([\"react\", \"html\"] as Lang[]).map((x) => (\n                        <button\n                          key={x}\n                          type=\"button\"\n                          aria-pressed={l === x}\n                          onClick={() => setLangs({ ...langs, [p.id]: x })}\n                          className={`h-9 rounded-md px-2.5 text-[12px] font-semibold ${ring} ${l === x ? \"bg-white text-stone-950 shadow-sm\" : \"text-stone-600 hover:text-stone-900\"}`}\n                        >\n                          {x === \"react\" ? \"React\" : \"HTML\"}\n                        </button>\n                      ))}\n                    </div>\n                  )}\n                  <span className=\"flex-1\" />\n                  <button\n                    type=\"button\"\n                    aria-expanded={isOpen}\n                    aria-controls={`code-${p.id}`}\n                    onClick={() => setOpen(isOpen ? null : p.id)}\n                    className={`inline-flex h-10 items-center gap-1.5 rounded-lg px-3 text-[12.5px] font-semibold text-stone-700 hover:bg-stone-100 ${ring}`}\n                  >\n                    <svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth={2} strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\" className=\"h-4 w-4\">\n                      <path d={CODE_ICON} />\n                    </svg>\n                    {isOpen ? \"Hide code\" : \"Code\"}\n                  </button>\n                  <button\n                    type=\"button\"\n                    onClick={() => copy(p)}\n                    aria-label={`Copy ${langName(l)} for ${p.name}`}\n                    className={`inline-flex h-10 items-center gap-1.5 rounded-lg px-3 text-[12.5px] font-semibold transition-colors ${ring} ${copied === p.id ? \"bg-emerald-700 text-white\" : \"bg-stone-900 text-white hover:bg-stone-700\"}`}\n                  >\n                    <svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth={2} strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\" className=\"h-3.5 w-3.5\">\n                      <path d={copied === p.id ? CHECK_ICON : COPY_ICON} />\n                    </svg>\n                    {copied === p.id ? \"Copied\" : \"Copy\"}\n                  </button>\n                </div>\n                {isOpen && (\n                  <pre\n                    id={`code-${p.id}`}\n                    tabIndex={0}\n                    aria-label={`${langName(l)} for ${p.name}`}\n                    className=\"max-h-[440px] overflow-auto rounded-b-2xl border-t border-stone-800 bg-[#121316] p-4 font-mono text-[12px] leading-[1.65] text-stone-200\"\n                  >\n                    <code>{codeOf(p)}</code>\n                  </pre>\n                )}\n              </li>\n            );\n          })}\n        </ul>\n        )}\n\n        {group === \"ref\" && (\n        <div className=\"mt-6\">\n          <h3 className=\"text-[17px] font-semibold tracking-tight text-stone-950\">{TEXT.refTitle}</h3>\n          <p className=\"mt-1 max-w-3xl text-[13px] leading-relaxed text-stone-600\">{TEXT.refNote}</p>\n          <div className=\"mt-4 overflow-x-auto rounded-xl border border-stone-200 bg-white\" tabIndex={0} role=\"region\" aria-label={TEXT.refTitle}>\n            <table className=\"w-full min-w-[600px] text-left text-[13px]\">\n              <thead className=\"bg-stone-50 text-stone-700\">\n                <tr>\n                  {REF_HEAD.map((h) => (\n                    <th key={h} scope=\"col\" className=\"px-4 py-2.5 font-semibold\">\n                      {h}\n                    </th>\n                  ))}\n                </tr>\n              </thead>\n              <tbody>\n                {REF_ROWS.map((r, i) => (\n                  <tr key={i} className=\"border-t border-stone-200 align-top\">\n                    {r.map((c, j) =>\n                      j === 0 ? (\n                        <th key={j} scope=\"row\" className=\"whitespace-nowrap px-4 py-2.5 font-mono text-[12px] font-medium text-stone-900\">\n                          {c}\n                        </th>\n                      ) : (\n                        <td key={j} className=\"px-4 py-2.5 leading-relaxed text-stone-700\">\n                          {c}\n                        </td>\n                      )\n                    )}\n                  </tr>\n                ))}\n              </tbody>\n            </table>\n          </div>\n        </div>\n        )}\n      </div>\n    </section>\n  );\n}\n"}]}
