CarsXE

Search docs

Search pages, components, and skills.

Autocomplete

A text input that suggests options as the user types. Queries are debounced through the delay prop so a burst of keystrokes makes a single request, and passing onQueryChange switches the component into async mode where the caller owns filtering and the supplied items render verbatim. Supports a dropdown trigger, multi-select chips, grouped and object suggestions, forced selection, loading status, and a minimum query length.

Installation

Import from the package. Do not run shadcn add in your app.

tsx
import { Autocomplete } from "@carsxe/design-system/components/autocomplete"

Usage

tsx
import {
  Autocomplete,
  AutocompleteContent,
  AutocompleteEmpty,
  AutocompleteInput,
  AutocompleteItem,
  AutocompleteList,
} from "@carsxe/design-system/components/autocomplete"

<Autocomplete items={makes} delay={300} onQueryChange={search}>
  <AutocompleteInput placeholder="Search vehicle make" />
  <AutocompleteContent>
    <AutocompleteEmpty>No makes found.</AutocompleteEmpty>
    <AutocompleteList>
      {(make) => (
        <AutocompleteItem key={make} value={make}>
          {make}
        </AutocompleteItem>
      )}
    </AutocompleteList>
  </AutocompleteContent>
</Autocomplete>

Debounced async suggestions

Queries fire 400ms after you stop typing, so a burst of keystrokes makes a single request.

Dropdown trigger and clear button

Multiple selection with chips

Grouped object suggestions

Force selection

Type something that is not a make, then click away — the input resets.

API Reference

PropTypeDefault
itemsT[] | { value, items }[]—
delaynumber250 (ms)
onQueryChange(query: string) => void—
minLengthnumber1
loadingbooleanfalse
filternull | (item, query) => boolean—
limitnumber—
itemToStringValue(item: T) => string—
multiplebooleanfalse
forceSelectionbooleanfalse
valuestring | T[]—
defaultValuestring | T[]—
onValueChange(value: string | T[]) => void—
onSelect(item: T) => void—
onUnselect(item: T) => void—
onClear() => void—
openboolean—
onOpenChange(open: boolean) => void—
autoHighlightboolean | "always"false
openOnInputClickbooleanfalse
disabledbooleanfalse
readOnlyboolean—
requiredboolean—
invalidbooleanfalse
namestring—