SearchCtrlK

  • ↑↓navigate
  • ↵open
  • escclose

Can’t find it? Contact us

Autocomplete

A text field with a styled suggestion list under it, for a "Where are you going?" box or an address field.

Suggested destinations
Brightwater LakeLakeside cabins, 2 h away
Calder PeaksSki town in the north
Sorrel BayBeach houses and coves
Old StonegateHistoric quarter, walkable
Harbour DistrictCity lofts near the water
Fenwick HollowVillage in the hills
View code
tsx
<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.

Terminal
npm add @sdxc/ui remix
typescript
import "@sdxc/ui/theme.css";

Or copy it into your project to edit it:

Terminal
sdxc ui add autocomplete

Usage

typescript
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

tsx
<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.

PropTypeRequiredDescription
idstringYesThe field's id, from which every other id the autocomplete needs derives.
labelstringNoThe field's accessible name; pass aria-labelledby instead to point at a visible label.
optionsArray<Option>YesThe suggestions, in the order the list shows them.
headingRemixNodeNoShown at the top of the list while the field is empty, such as "Suggested destinations".
emptyLabelRemixNodeNoShown in the list when nothing matches. @default "No matches"
valueNamestringNoNames 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.
mixTagProps<"div">["mix"]NoStyling for the wrapper.
partsPartsPropsNoPer-part styling.

Also accepts everything in Omit< TagProps<"input">, "type" | "list" | "role" | "children" | "mix" | "value" | "color" >.

@sdxc/ui

Can’t find it? Contact us