{
  "$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": [
    "react-aria-components"
  ],
  "registryDependencies": [
    "combobox"
  ],
  "files": [
    {
      "path": "registry/ui/combobox-story/combobox-aria.stories.tsx",
      "content": "import { expect, userEvent, waitFor, within } from \"storybook/test\";\nimport type { Meta, StoryObj } from \"@storybook/nextjs-vite\";\nimport {\n  Combobox,\n  ComboboxChip,\n  ComboboxChipList,\n  ComboboxChips,\n  ComboboxChipsInput,\n  ComboboxContent,\n  ComboboxEmpty,\n  ComboboxInput,\n  ComboboxItem,\n  ComboboxList,\n} from \"@/components/ui/combobox\";\n\nconst frameworks = [\n  \"Next.js\",\n  \"SvelteKit\",\n  \"Nuxt.js\",\n  \"Remix\",\n  \"Astro\",\n] as const;\n\nfunction FrameworkPicker({\n  isDisabled = false,\n  showClear = false,\n}: {\n  isDisabled?: boolean;\n  showClear?: boolean;\n}) {\n  return (\n    <Combobox\n      aria-label=\"Framework\"\n      allowsEmptyCollection\n      isDisabled={isDisabled}\n      defaultValue={showClear ? frameworks[0] : undefined}\n    >\n      <ComboboxInput placeholder=\"Select a framework\" showClear={showClear} />\n      <ComboboxContent>\n        <ComboboxList\n          renderEmptyState={() => (\n            <ComboboxEmpty>No items found.</ComboboxEmpty>\n          )}\n        >\n          {frameworks.map((item) => (\n            <ComboboxItem key={item} id={item} textValue={item}>\n              {item}\n            </ComboboxItem>\n          ))}\n        </ComboboxList>\n      </ComboboxContent>\n    </Combobox>\n  );\n}\n\nfunction ComboboxMultiple() {\n  return (\n    <Combobox\n      aria-label=\"Frameworks\"\n      selectionMode=\"multiple\"\n      defaultValue={[frameworks[0]]}\n      allowsEmptyCollection\n    >\n      <ComboboxChips>\n        <ComboboxChipList<{ name: string }>>\n          {(value) => (\n            <ComboboxChip id={value.name} textValue={value.name}>\n              {value.name}\n            </ComboboxChip>\n          )}\n        </ComboboxChipList>\n        <ComboboxChipsInput />\n      </ComboboxChips>\n      <ComboboxContent>\n        <ComboboxList\n          renderEmptyState={() => (\n            <ComboboxEmpty>No items found.</ComboboxEmpty>\n          )}\n        >\n          {frameworks.map((item) => (\n            <ComboboxItem\n              key={item}\n              id={item}\n              textValue={item}\n              value={{ name: item }}\n            >\n              {item}\n            </ComboboxItem>\n          ))}\n        </ComboboxList>\n      </ComboboxContent>\n    </Combobox>\n  );\n}\n\n/** Search a list of choices and select one or more matching items. */\nconst meta = {\n  id: \"ui-aria-combobox\",\n  title: \"ui/Combobox\",\n  component: Combobox,\n  tags: [\"autodocs\"],\n  parameters: { layout: \"centered\" },\n  render: () => <FrameworkPicker />,\n} satisfies Meta<typeof Combobox>;\nexport default meta;\ntype Story = StoryObj<typeof meta>;\n\n/** Search a list of choices and select one or more matching items. */\nexport const Default: Story = {};\n\n/** Disable the framework picker. */\nexport const Disabled: Story = { render: () => <FrameworkPicker isDisabled /> };\n\n/** Clear the selected framework with the reset button. */\nexport const WithClear: Story = { render: () => <FrameworkPicker showClear /> };\n\n/** Display selected frameworks as removable chips. */\nexport const Multiple: Story = { render: () => <ComboboxMultiple /> };\n\n/** Filter frameworks and select the matching option. */\nexport const ShouldSearchAndSelect: Story = {\n  tags: [\"!dev\", \"!autodocs\"],\n  play: async ({ canvasElement, canvas }) => {\n    const input = canvas.getByRole(\"combobox\", { name: \"Framework\" });\n    const body = within(canvasElement.ownerDocument.body);\n    await userEvent.type(input, \"Svelt\");\n    const option = await body.findByRole(\"option\", { name: \"SvelteKit\" });\n    await expect(body.getAllByRole(\"option\")).toHaveLength(1);\n    await userEvent.click(option);\n    await waitFor(() => expect(input).toHaveValue(\"SvelteKit\"));\n    await expect(input).toHaveAttribute(\"aria-expanded\", \"false\");\n  },\n};\n\n/** Clear a preselected framework. */\nexport const ShouldClearSelection: Story = {\n  ...WithClear,\n  tags: [\"!dev\", \"!autodocs\"],\n  play: async ({ canvas }) => {\n    const input = canvas.getByRole(\"combobox\", { name: \"Framework\" });\n    await expect(input).toHaveValue(\"Next.js\");\n    await userEvent.click(canvas.getByRole(\"button\", { name: \"Clear\" }));\n    await expect(input).toHaveValue(\"\");\n  },\n};\n\n/** Remove a selected framework without disturbing another chip. */\nexport const ShouldAddAndRemoveSelection: Story = {\n  ...Multiple,\n  tags: [\"!dev\", \"!autodocs\"],\n  play: async ({ canvas, canvasElement }) => {\n    const input = canvas.getByRole(\"combobox\", { name: \"Frameworks\" });\n    const body = within(canvasElement.ownerDocument.body);\n    await userEvent.type(input, \"Svelt\");\n    await userEvent.click(\n      await body.findByRole(\"option\", { name: \"SvelteKit\" }),\n    );\n    await userEvent.keyboard(\"{Escape}\");\n    await userEvent.click(\n      await canvas.findByRole(\"button\", { name: /remove SvelteKit/i }),\n    );\n    await waitFor(() =>\n      expect(\n        canvas.queryByRole(\"button\", { name: /remove SvelteKit/i }),\n      ).not.toBeInTheDocument(),\n    );\n    await expect(\n      canvas.getByRole(\"button\", { name: /remove Next.js/i }),\n    ).toBeVisible();\n  },\n};\n\n/** Use the arrow key to open the list and Enter to select the focused framework. */\nexport const ShouldNavigateWithKeyboard: Story = {\n  tags: [\"!dev\", \"!autodocs\"],\n  play: async ({ canvas, canvasElement }) => {\n    const input = canvas.getByRole(\"combobox\", { name: \"Framework\" });\n    await userEvent.click(input);\n    await userEvent.keyboard(\"{ArrowDown}\");\n    const option = await within(canvasElement.ownerDocument.body).findByRole(\n      \"option\",\n      { name: \"Next.js\" },\n    );\n    await waitFor(() =>\n      expect(input).toHaveAttribute(\"aria-activedescendant\", option.id),\n    );\n    await userEvent.keyboard(\"{Enter}\");\n    await waitFor(() => expect(input).toHaveValue(\"Next.js\"));\n    await expect(input).toHaveAttribute(\"aria-expanded\", \"false\");\n  },\n};\n",
      "type": "registry:component",
      "target": "@ui/combobox.stories.tsx"
    }
  ],
  "categories": [
    "ui",
    "storybook",
    "combobox"
  ],
  "type": "registry:component"
}