# Autocomplete

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

```ts
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="where" name="where" label="Where to?" heading="Suggested destinations"
	valueName="placeId" options={[{ value: "lis", label: "Lisbon", description: "Portugal" }]} />
```

```tsx
<Autocomplete id="q" name="q" variant="bare" aria-labelledby="where-label" options={places} />
```

## Props

| Prop | Type | Description |
| --- | --- | --- |
| `id` | `string` | The field's `id`, from which every other id the autocomplete needs derives. |
| `label?` | `string` | The field's accessible name; pass `aria-labelledby` instead to point at a visible label. |
| `options` | `Array<Option>` | The suggestions, in the order the list shows them. |
| `heading?` | `RemixNode` | Shown at the top of the list while the field is empty, such as "Suggested destinations". |
| `emptyLabel?` | `RemixNode` | Shown in the list when nothing matches. @default "No matches" |
| `valueName?` | `string` | Names a hidden field carrying the picked option's `value`, emptied once the text is edited. |
| `variant?` | `"field" \| "bare"` | `"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"]` | Styling for the wrapper. |
| `parts?` | `PartsProps` | Per-part styling. |

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

