Autocomplete
Suggest completions while allowing free text.
Installation
pnpm dlx shadcn@4.18.0 add @siteplane/autocompleteComplete the one-time setup first. Registry JSON lists source files and dependencies.
For this page’s examples, also install:
pnpm dlx shadcn@4.18.0 add @siteplane/button @siteplane/form @siteplane/inputField is installed with Input.
Usage
import {
Autocomplete,
AutocompleteInput,
AutocompletePopup,
AutocompleteEmpty,
AutocompleteList,
AutocompleteItem,
} from "@/siteplane/components/autocomplete";
<Autocomplete items={["Design"]}>
<AutocompleteInput aria-label="Workspace" />
<AutocompletePopup>
<AutocompleteEmpty>No matching workspaces.</AutocompleteEmpty>
<AutocompleteList>
{(item: string) => (
<AutocompleteItem key={item} value={item}>
{item}
</AutocompleteItem>
)}
</AutocompleteList>
</AutocompletePopup>
</Autocomplete>;Composition
Autocomplete
├── AutocompleteInput
└── AutocompletePopup
├── AutocompleteStatus (optional)
├── AutocompleteEmpty
└── AutocompleteList → AutocompleteItemControlled value and clear
The clear button updates the controlled value. Type a non-matching query to see the empty result.
Grouped suggestions
Pass groups as items and render each with AutocompleteGroup, AutocompleteGroupLabel and AutocompleteCollection. itemToStringValue turns an object item into the text that fills the input and drives filtering.
Limit results
Set limit to cap how many suggestions the list shows, and use AutocompleteStatus to say how many more match. useAutocompleteFilter returns the matching function the list uses by default, so the count stays in sync.
Variants and disabled
variant belongs to the input. Disabled prevents input interaction.
Sizes
size belongs to the input. Omit it to inherit the provider's control size.
Form integration
Place the autocomplete in a Field with a name; the submitted value is the typed text, which can differ from every suggestion.
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
Autocomplete | sm | md | lg | xl | number | provider / lg | Visual size, or numeric native input size. |
Autocomplete | default | elevated | inset | default | Input surface. |
Autocomplete | boolean | false | Show popup toggle. |
Autocomplete | boolean | false | Show clear action. |
Autocomplete | ReactNode | unset | Leading content. |
Autocomplete | Trigger.Props / Clear.Props | unset | Configure generated action buttons. |
Autocomplete | Positioner side / alignment | bottom / start | Preferred position. |
Autocomplete | offsets | 4 / unset | Gap and alignment correction. |
Autocomplete | Positioner anchor | trigger/input | Custom anchor. |
Autocomplete | Portal.Props | unset | Portal options. |
value / default | string | uncontrolled | Editable text, including arbitrary text. |
on | (value, eventDetails) => void | unset | Value callback. |
on | (open, eventDetails) => void | unset | Popup visibility callback. |
Autocomplete | boolean | false | Remove the input surface. |
Autocomplete resets uncontrolled text when its associated native form resets. It does not add selected-item or multiple-selection semantics. useAutocompleteFilter is the foundation filtering hook. Input accepts foundation render and native ref contracts, unlike ComboboxInput’s narrower API.
AutocompleteList renders the filtered collection; Item represents a suggestion; Empty displays no results; Status provides status feedback. AutocompleteGroup, AutocompleteGroupLabel, AutocompleteSeparator and AutocompleteRow structure options. AutocompleteValue renders the current value; AutocompleteCollection supplies foundation collection composition. AutocompleteTrigger and AutocompleteClear are independently exported actions; their default render uses kit Buttons. Popup includes Portal and Positioner; AutocompleteList adds the ScrollArea. AutocompletePrimitive exports the namespace. Remaining root item-to-string/filter, keyboard, validation, disabled, readOnly, form, events and refs follow Base UI Autocomplete. Styled className props are strings. No independent fetch or loading service is supplied.
AutocompleteTrigger and AutocompleteClear accept their corresponding foundation props and default to a ghost Button with field-action profile and icon-xs size. Supply an accessible name when composing either action separately. AutocompleteGroup, AutocompleteGroupLabel, AutocompleteRow, AutocompleteSeparator, AutocompleteValue, and AutocompleteCollection accept their matching foundation part props with kit styling; they add no owned state API.
Usage notes
Arrow keys navigate suggestions, Enter accepts and Escape dismisses. Keep a visible label in a production form. For async data, the application owns fetching, stale-result handling and pending/error status; render those states through Status and the surrounding field. See Choosing selection controls.