Skip to content
Logic2BUI

Search docs

Search components and documentation

New
Menu

Autocomplete

A free-text input with a filtered suggestion list — the editable ARIA combobox pattern.

Installation

npx logic2b@next add autocomplete

Usage

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.

Generated JSX
<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.

View JSON

AutocompleteProps

Type
interface 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

Component

A 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
PropTypeRequiredDefaultDescription
optionsstring[]Yes—The suggestion list, filtered against what the user types.
valuestringNo——
defaultValuestringNo——
onValueChange(value: string) => voidNo——
emptyMessagestringNo"No results."Shown when nothing matches. Default `"No results."`.

Accessibility contract

Machine-readable behavior and consumer responsibilities for autocomplete.

View JSON
Support
Authored behavior
Pattern
editable combobox
Keyboard interactions for autocomplete
KeysBehavior
ArrowUp ArrowDownMove the active suggestion.
EnterChoose the active suggestion.
EscapeClose 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.