Installation
npx logic2b@next add autocompleteUsage
import { Autocomplete } from "@/components/ui/autocomplete"
const [value, setValue] = React.useState("")
<Autocomplete
options={["Next.js", "Vite", "Astro"]}
value={value}
onValueChange={setValue}
placeholder="Search framework..."
/>
The list filters against what the user types (case-insensitive includes), but
the input accepts arbitrary text — that’s what separates it from the
select-style Combobox. Reach for Autocomplete
when the suggestions are hints (a search box, a tag entry); reach for Combobox
when the value must come from a fixed set.
Keyboard
- ↓ / ↑ move the active suggestion.
- Enter picks the active suggestion.
- Esc closes the list, keeping what you typed.
Live playground
Edit the component props and inspect the exact JSX before copying it. The preview loads only when this section enters the viewport.
<Autocomplete
options={["Accordion", "Button", "Dialog", "Tabs", "Tooltip"]}
defaultValue="Button"
placeholder="Find a component…"
aria-label="Component search"
/>API reference
Generated from the public TypeScript exports in src/ui/autocomplete.tsx.
AutocompleteProps
Typeinterface AutocompleteProps extends Omit< React.ComponentProps<"input">, "value" | "defaultValue" | "onChange" > { /** The suggestion list, filtered against what the user types. */ options: string[] value?: string defaultValue?: string onValueChange?: (value: string) => void /** Shown when nothing matches. Default `"No results."`. */ emptyMessage?: string }Autocomplete
ComponentA free-text input with a filtered suggestion list — the editable ARIA combobox pattern. Unlike a select-style combobox it accepts arbitrary text; the list just offers matches. Fully keyboard-driven (↑/↓ to move, Enter to pick, Esc to close) and dependency-free.
Props: AutocompleteProps| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
options | string[] | Yes | — | The suggestion list, filtered against what the user types. |
value | string | No | — | — |
defaultValue | string | No | — | — |
onValueChange | (value: string) => void | No | — | — |
emptyMessage | string | No | "No results." | Shown when nothing matches. Default `"No results."`. |
Accessibility contract
Machine-readable behavior and consumer responsibilities for autocomplete.
- Support
- Authored behavior
- Pattern
- editable combobox
| Keys | Behavior |
|---|---|
| ArrowUp ArrowDown | Move the active suggestion. |
| Enter | Choose the active suggestion. |
| Escape | Close the open surface and restore focus. |
Built-in semantics
- Uses combobox/listbox/option semantics with aria-expanded, aria-controls and aria-activedescendant.
Consumer responsibilities
- Provide a label and ensure arbitrary typed text is valid for the use case.