Autocomplete
A text field with a styled suggestion list under it, for a "Where are you going?" box or an address field.
View code
<form method="get" action="/stays">
<Autocomplete
id="where"
name="where"
label="Where to?"
placeholder="Search destinations"
heading="Suggested destinations"
valueName="placeId"
options={[
{ value: "brl", label: "Brightwater Lake", description: "Lakeside cabins", icon: <TreePineIcon /> },
{ value: "cap", label: "Calder Peaks", description: "Ski town", icon: <MountainIcon /> },
// …
]}
/>
</form>Installation
An ordinary dependency: install it, import the theme once, and import the component where it is used.
npm add @sdxc/ui remiximport "@sdxc/ui/theme.css";Or copy it into your project to edit it:
sdxc ui add autocompleteUsage
import { Autocomplete } from "@sdxc/ui";Renders the field, its <datalist>, a hidden list of styled options and the island that
swaps one for the other. Picking fires change and an autocomplete-select event on the
field with { value, label }; Enter on an option never submits the form.
Examples
<Autocomplete id="q" name="q" variant="bare" aria-labelledby="where-label" options={places} />Props
Read from the component's own types, so every prop, every default and every allowed value is listed.
| Prop | Type | Required | Description |
|---|---|---|---|
id | string | Yes | The field's id, from which every other id the autocomplete needs derives. |
label | string | No | The field's accessible name; pass aria-labelledby instead to point at a visible label. |
options | Array<Option> | Yes | The suggestions, in the order the list shows them. |
heading | RemixNode | No | Shown at the top of the list while the field is empty, such as "Suggested destinations". |
emptyLabel | RemixNode | No | Shown in the list when nothing matches. @default "No matches" |
valueName | string | No | Names a hidden field carrying the picked option's value, emptied once the text is edited. |
variant | "field" | "bare" | No | "field" draws the bordered input; "bare" drops its border, background, padding and focus ring, for a field set inside a pill that draws them with :focus-within. |
mix | TagProps<"div">["mix"] | No | Styling for the wrapper. |
parts | PartsProps | No | Per-part styling. |
Also accepts everything in Omit<
TagProps<"input">,
"type" | "list" | "role" | "children" | "mix" | "value" | "color"
>.