# Combobox

> A single-choice text field over a closed set of options — typing filters a portalled listbox, and a value outside the list can never be selected.

- Package: `fancy-ui-react` (React 18/19 + Tailwind CSS v4)
- Category: Forms
- Tags: combobox, dropdown, listbox, filter, form, compound, accessibility
- Types: `ComboboxProps`, `ComboboxOption`, `ComboboxContext`
- Docs: https://fancy-ui.rama.app/docs/components/combobox
- Source: https://github.com/RamaHerbin/fancy-ui/tree/main/react/src/components/combobox

## Import

```tsx
import { Combobox } from 'fancy-ui-react';
```

Setup (once per project): `npm install fancy-ui-react`, then put these lines in your main CSS file (the stylesheet import goes right after `@import "tailwindcss";`):

```css
@import "tailwindcss";
@import "fancy-ui-react/tailwind.css";
```

and import the component styles once in the app entry: `import "fancy-ui-react/styles.css";`. Full guide: https://fancy-ui.rama.app/llms.txt

The names below are the ones to write in React; when one differs from the Svelte name, the Svelte name follows in parentheses. `class` becomes `className`, a callback takes the name the React port declares (`onclick` becomes `onClick`), snippets become `ReactNode` props (render functions when they take arguments) and the default snippet is `children`. Divergences: https://github.com/RamaHerbin/fancy-ui/tree/main/react#divergences-from-the-svelte-api

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `options` (required) | `ComboboxOption[]` | — | The closed set of selectable options. |
| `value` | `string` | `""` | The selected option's value, bindable — "" means nothing is selected. |
| `onValueChange` | `(value: string) => void` | — | Called whenever the selection commits. |
| `placeholder` | `string` | — | Shown while the field is empty and nothing is selected. |
| `disabled` | `boolean` | `false` | Blocks focus and typing; excluded from form submission. |
| `required` | `boolean` | `false` | Native required, on the visible field. |
| `invalid` | `boolean` | `false` | Drives the error border and aria-invalid. |
| `id` | `string` | — | Element id. |
| `name` | `string` | — | Native name — submitted via a hidden input carrying value, not the visible label. |
| `label` | `string` | — | Accessible name — for a control with no visible Label next to it. |
| `filter` | `(option: ComboboxOption, query: string) => boolean` | — | Matches an option against the current query. Default: case-insensitive substring on label. |
| `emptyMessage` | `string` | `"No results"` | Shown in the panel when no option matches the current query. |
| `className` (Svelte `class`) | `string` | — | Additional CSS classes. |
| `ref` | `HTMLInputElement \| null` | `null` | Bindable reference to the input element. |
| `sound` | `boolean` | `false` | Plays the select cue when an option is committed, once the user has enabled sound |

## Example

```tsx
import { useState } from "react";
import { Combobox } from "fancy-ui-react";

const frameworks = [
	{ value: "svelte-5", label: "Svelte 5" },
	{ value: "sveltekit", label: "SvelteKit" },
	{ value: "react", label: "React" },
	{ value: "vue", label: "Vue" },
];

export function ComboboxExample() {
	const [framework, setFramework] = useState("");

	return (
		<Combobox
			sound
			options={frameworks}
			value={framework}
			onValueChange={setFramework}
			label="Framework"
			placeholder="Search…"
		/>
	);
}
```
