kemiljk

Combobox

Component

About

A searchable, filterable dropdown input that lets a user type to narrow a list of options and select one, built on the WAI-ARIA 1.2 combobox pattern with keyboard navigation and optional grouped results.

Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Combobox to your project and fits it to your theme.

Code

How Combobox is used: the demo's code. The component's own source comes with a free account.

Usage.tsx

import Combobox from "@/components/ui/combobox";
import { useState } from "react";

const groups = [
  {
    id: "frontend",
    label: "Frontend",
    items: [
      { value: "astro", label: "Astro" },
      { value: "react", label: "React" },
    ],
  },
  {
    id: "backend",
    label: "Backend",
    items: [
      { value: "bun", label: "Bun" },
      { value: "node", label: "Node.js" },
    ],
  },
];

export default function ComboboxCompositionDemo() {
  const [value, setValue] = useState("");

  return (
    <div style={{ maxInlineSize: "22rem" }}>
      <Combobox label="Framework">
        <Combobox.Input
          value={value}
          onValueChange={setValue}
          placeholder="Search frameworks"
        />
        <Combobox.List>
          {groups.map((group) => (
            <Combobox.Group key={group.id} id={group.id} heading={group.label}>
              {group.items.map((option) => (
                <Combobox.Item
                  key={option.value}
                  id={`framework-${option.value}`}
                  value={option.value}
                  onSelect={() => setValue(option.label)}
                >
                  {({ active, selected }) => (
                    <span
                      style={{
                        display: "flex",
                        justifyContent: "space-between",
                        fontWeight: active ? 650 : undefined,
                      }}
                    >
                      {option.label}
                      {selected ? (
                        <span aria-hidden="true">Selected</span>
                      ) : null}
                    </span>
                  )}
                </Combobox.Item>
              ))}
            </Combobox.Group>
          ))}
        </Combobox.List>
      </Combobox>
    </div>
  );
}

More by kemiljk

View all
  • Switch

    Switch

    8
  • Color Picker

    Color Picker

    1
  • Progress

    Progress

  • Navigation Menu

    Navigation Menu

  • Toggle

    Toggle

  • Label

    Label

  • Radio Group

    Radio Group

  • Avatar

    Avatar