SearchCtrlK

  • ↑↓navigate
  • ↵open
  • escclose

Can’t find it? Contact us

autocomplete

Turns a server-rendered Autocomplete into an ARIA combobox.

tsx
import { autocomplete } from "@sdxc/ui/mixins";
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
// Autocomplete's island runs autocomplete(), so the suggestions filter as you type.
<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>

Usage

Enhances the [data-slot="autocomplete"] around the host into a combobox over its styled list, and undoes nothing on removal beyond dropping its listeners. Mount it on a hidden element inside the autocomplete, which is how the island that carries it renders.

Signature

typescript
autocomplete(): MixinDescriptor<HTMLElement>

Examples

tsx
<span hidden mix={autocomplete()} />

The events, constants and types its module publishes, each imported from @sdxc/ui/mixins too.

Constant

AUTOCOMPLETE_SELECT_EVENT

Name of the bubbling event a pick dispatches on the field, carrying AutocompleteSelectDetail.

typescript
const AUTOCOMPLETE_SELECT_EVENT = "autocomplete-select"
Interface

AutocompleteSelectDetail

The option a pick chose, as the detail of AUTOCOMPLETE_SELECT_EVENT.

MemberTypeRequiredDescription
valuestringYes
labelstringYes
@sdxc/ui

Can’t find it? Contact us