{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "combobox-story",
  "title": "Combobox Story",
  "author": "Lloyd Richards <lloyd.d.richards@gmail.com>",
  "description": "Interactive Storybook stories demonstrating combobox usage and variants",
  "dependencies": [
    "@base-ui/react"
  ],
  "registryDependencies": [
    "combobox"
  ],
  "files": [
    {
      "path": "registry/ui/combobox-story/combobox-radix.stories.tsx",
      "content": "import { Combobox as ComboboxPrimitive } from \"@base-ui/react\";\nimport type { Meta, StoryObj } from \"@storybook/nextjs-vite\";\nimport { useState } from \"react\";\nimport { expect, userEvent, waitFor, within } from \"storybook/test\";\n\nimport {\n  Combobox,\n  ComboboxChip,\n  ComboboxChips,\n  ComboboxChipsInput,\n  ComboboxContent,\n  ComboboxEmpty,\n  ComboboxInput,\n  ComboboxItem,\n  ComboboxList,\n  ComboboxValue,\n  useComboboxAnchor,\n} from \"@/components/ui/combobox\";\n\nconst frameworks = [\"Next.js\", \"SvelteKit\", \"Nuxt.js\", \"Remix\", \"Astro\"];\n\n/** Search a list of suggestions and select one or more values. Both registry variants use the Base UI combobox primitive. */\nconst meta = {\n  id: \"ui-radix-combobox\",\n  title: \"ui/Combobox\",\n  component: Combobox,\n  tags: [\"autodocs\"],\n  parameters: { layout: \"centered\" },\n  render: (args) => (\n    <Combobox {...args} items={frameworks}>\n      <ComboboxInput\n        aria-label=\"Framework\"\n        placeholder=\"Select a framework\"\n        className=\"w-72\"\n      />\n      <ComboboxContent>\n        <ComboboxEmpty>No frameworks found.</ComboboxEmpty>\n        <ComboboxList>\n          {(item: string) => (\n            <ComboboxItem key={item} value={item} disabled={item === \"Nuxt.js\"}>\n              {item}\n            </ComboboxItem>\n          )}\n        </ComboboxList>\n      </ComboboxContent>\n    </Combobox>\n  ),\n} satisfies Meta<typeof Combobox>;\n\nexport default meta;\ntype Story = StoryObj<typeof meta>;\n\n/** Search the frameworks, with Nuxt.js unavailable for selection. */\nexport const Default: Story = {};\n\n/** Disable the combobox when the selection cannot be changed. */\nexport const Disabled: Story = { args: { disabled: true } };\n\n/** Start with a selection and let the user clear it. */\nexport const WithClear: Story = {\n  render: () => (\n    <Combobox items={frameworks} defaultValue=\"Next.js\">\n      <ComboboxInput\n        aria-label=\"Framework\"\n        placeholder=\"Select a framework\"\n        showTrigger={false}\n        className=\"w-72\"\n      >\n        <ComboboxPrimitive.Clear\n          aria-label=\"Clear selection\"\n          className=\"px-2 text-xs\"\n        >\n          Clear\n        </ComboboxPrimitive.Clear>\n      </ComboboxInput>\n      <ComboboxContent>\n        <ComboboxEmpty>No frameworks found.</ComboboxEmpty>\n        <ComboboxList>\n          {(item: string) => (\n            <ComboboxItem key={item} value={item}>\n              {item}\n            </ComboboxItem>\n          )}\n        </ComboboxList>\n      </ComboboxContent>\n    </Combobox>\n  ),\n};\n\nfunction MultipleExample() {\n  const [value, setValue] = useState<string[]>([\"Next.js\"]);\n  const anchor = useComboboxAnchor();\n\n  return (\n    <Combobox\n      items={frameworks}\n      multiple\n      value={value}\n      onValueChange={setValue}\n    >\n      <ComboboxChips ref={anchor} className=\"w-80\">\n        <ComboboxValue>\n          {value.map((item) => (\n            <ComboboxChip key={item} showRemove={false}>\n              {item}\n              <ComboboxPrimitive.ChipRemove\n                aria-label=\"Remove selection\"\n                className=\"px-1\"\n              >\n                ×\n              </ComboboxPrimitive.ChipRemove>\n            </ComboboxChip>\n          ))}\n        </ComboboxValue>\n        <ComboboxChipsInput\n          aria-label=\"Frameworks\"\n          placeholder=\"Add a framework\"\n        />\n      </ComboboxChips>\n      <ComboboxContent anchor={anchor}>\n        <ComboboxEmpty>No frameworks found.</ComboboxEmpty>\n        <ComboboxList>\n          {(item: string) => (\n            <ComboboxItem key={item} value={item}>\n              {item}\n            </ComboboxItem>\n          )}\n        </ComboboxList>\n      </ComboboxContent>\n    </Combobox>\n  );\n}\n\n/** Select several frameworks and remove individual selections with their chip buttons. */\nexport const Multiple: Story = { render: () => <MultipleExample /> };\n\n/** Searching narrows the suggestions and selecting an option updates the input. */\nexport const ShouldSearchAndSelect: Story = {\n  tags: [\"!dev\", \"!autodocs\"],\n  play: async ({ canvasElement }) => {\n    const canvas = within(canvasElement);\n    const body = within(canvasElement.ownerDocument.body);\n    const input = canvas.getByRole(\"combobox\", { name: \"Framework\" });\n    await userEvent.type(input, \"sve\");\n    await userEvent.click(\n      await body.findByRole(\"option\", { name: \"SvelteKit\" }),\n    );\n    await expect(input).toHaveValue(\"SvelteKit\");\n    await expect(input).toHaveAttribute(\"aria-expanded\", \"false\");\n  },\n};\n\n/** An unmatched search explains that there are no suggestions. */\nexport const ShouldShowEmptyResults: Story = {\n  tags: [\"!dev\", \"!autodocs\"],\n  play: async ({ canvasElement }) => {\n    const input = within(canvasElement).getByRole(\"combobox\", {\n      name: \"Framework\",\n    });\n    const body = within(canvasElement.ownerDocument.body);\n    await userEvent.type(input, \"unavailable framework\");\n    await expect(await body.findByText(\"No frameworks found.\")).toBeVisible();\n    await expect(body.queryByRole(\"option\")).not.toBeInTheDocument();\n  },\n};\n\n/** Arrow keys select a suggestion, and Escape dismisses the reopened list. */\nexport const ShouldNavigateWithKeyboard: Story = {\n  tags: [\"!dev\", \"!autodocs\"],\n  play: async ({ canvasElement }) => {\n    const input = within(canvasElement).getByRole(\"combobox\", {\n      name: \"Framework\",\n    });\n    await userEvent.click(input);\n    await userEvent.keyboard(\"{ArrowDown}{Enter}\");\n    await expect(input).toHaveValue(\"Next.js\");\n    await userEvent.keyboard(\"{ArrowDown}\");\n    await expect(input).toHaveAttribute(\"aria-expanded\", \"true\");\n    await userEvent.keyboard(\"{Escape}\");\n    await expect(input).toHaveAttribute(\"aria-expanded\", \"false\");\n    await expect(input).toHaveValue(\"Next.js\");\n  },\n};\n\n/** Clearing removes the selected value and returns the input to its placeholder. */\nexport const ShouldClearSelection: Story = {\n  ...WithClear,\n  tags: [\"!dev\", \"!autodocs\"],\n  play: async ({ canvasElement }) => {\n    const canvas = within(canvasElement);\n    const input = canvas.getByRole(\"combobox\", { name: \"Framework\" });\n    await expect(input).toHaveValue(\"Next.js\");\n    await userEvent.click(\n      canvas.getByRole(\"button\", { name: \"Clear selection\" }),\n    );\n    await expect(input).toHaveValue(\"\");\n  },\n};\n\n/** Multiple selection adds a chip, and its remove button removes only that value. */\nexport const ShouldAddAndRemoveSelection: Story = {\n  ...Multiple,\n  tags: [\"!dev\", \"!autodocs\"],\n  play: async ({ canvasElement }) => {\n    const canvas = within(canvasElement);\n    const body = within(canvasElement.ownerDocument.body);\n    await userEvent.type(\n      canvas.getByRole(\"combobox\", { name: \"Frameworks\" }),\n      \"sve\",\n    );\n    await userEvent.click(\n      await body.findByRole(\"option\", { name: \"SvelteKit\" }),\n    );\n    await expect(canvas.getByText(\"SvelteKit\")).toBeVisible();\n    await userEvent.click(\n      within(canvas.getByText(\"SvelteKit\")).getByRole(\"button\", {\n        name: \"Remove selection\",\n      }),\n    );\n    await waitFor(() =>\n      expect(canvas.queryByText(\"SvelteKit\")).not.toBeInTheDocument(),\n    );\n    await expect(canvas.getByText(\"Next.js\")).toBeVisible();\n  },\n};\n",
      "type": "registry:component",
      "target": "@ui/combobox.stories.tsx"
    }
  ],
  "categories": [
    "ui",
    "storybook",
    "combobox"
  ],
  "type": "registry:component"
}