autocomplete
Turns a server-rendered Autocomplete into an ARIA combobox.
import { autocomplete } from "@sdxc/ui/mixins";View code
// 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
autocomplete(): MixinDescriptor<HTMLElement>Examples
<span hidden mix={autocomplete()} />Used with it
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.
const AUTOCOMPLETE_SELECT_EVENT = "autocomplete-select"Interface
AutocompleteSelectDetail
The option a pick chose, as the detail of AUTOCOMPLETE_SELECT_EVENT.
| Member | Type | Required | Description |
|---|---|---|---|
value | string | Yes | |
label | string | Yes |