Autocomplete
Free text with suggestions, where any value is valid and suggestions help, such as addresses: Base UI's Autocomplete, inside a Field. Site and collection search compose it in Search.
import { Autocomplete } from '@fairgarden/design/forms/autocomplete'
Suggestions are { value, label? } objects, or titled groups; a chosen suggestion only fills the input, and Enter submits the typed text. There is no ✓, because nothing stays selected. When the server filters the suggestions, pass filter={null} and the current items.
Suggestions and states
Suggestions and states
No row is highlighted until the arrow keys move; the highlighted row takes the --primary4 soft fill and the --border-size-2-25 start bar, and matches are marked by weight. loading shows "Searching…" in a polite live region; error shows the danger glyph and a message instead of silently closing; the empty row keeps what the user typed.
Pick a suggestion or keep typing.
Primary and secondary
Primary and secondary
primary sets the box, value and icons; secondary is unused at rest and becomes the danger scale while invalid.
On grounds
On paper and forest
The box follows its ground; the popup renders in a portal as the white scope.
paper
forest
Outline morph
On by default: the box's focus ring, which shows on any focus, grows into the popup's frame as it opens and shrinks back onto the ring as it closes. Explicit opens morph (the chevron with showTrigger, the arrow keys), and so does the first open after focus arrives, even when typing caused it. After that, opens and closes caused by typing are instant, so the list keeps up with the keys, and a list that resizes as results filter does so on its own. Typing is never delayed. morph={false} opens and closes the popup at once; see Outline Morph.
API Reference
A Base UI Autocomplete inside a Field. The input keeps any text: a
suggestion only fills it, and Enter submits the typed text. No row is
highlighted until the arrow keys move.
| Prop | Type | Description |
|---|---|---|
aria-label | | Names the input when no visible label exists. Prefer a |
clearLabel | | The clear בs accessible name. Default “Clear”. |
emptyText | | The empty row. Default “No matches for ‘[query]'". Keep what the user typed. |
error | | A fetch failure, shown with the danger glyph instead of silently closing. |
icon | | A leading icon in the box, such as |
items | | The suggestions, or titled groups. Pass |
loading | | Shows the loading row (“Searching…") while suggestions load. |
loadingText | | The loading row’s words. Default “Searching…". |
morph | | The outline morph: the box’s focus ring grows into the popup’s frame as
it opens and shrinks back onto the ring as it closes. Opens you ask for
(the chevron with |
placeholder | | The input’s placeholder, ending in “…"; never the label. |
plate | | The box face becomes a nested |
primary | | Primary Radix scale: edge, value, icons and focus ring. Never defaulted [D133]. |
secondary | | Secondary Radix scale. Unused at rest; the danger scale while invalid. |
showTrigger | | Shows the chevron that opens the full list. Default |
triggerLabel | | The chevron’s accessible name. Default “Show suggestions”. |
className | | Class names for the box, added after the module’s own. |
autocomplete
type autocomplete = autocompleteAutocompleteOption
One suggestion: the text it puts in the input, and optional display words.
type AutocompleteOption = {
/** The text the suggestion fills in. */
value: string;
/** The words shown in the list. Default: `value`. */
label?: string;
disabled?: boolean;
}AutocompleteOptionGroup
A titled group of suggestions.
type AutocompleteOptionGroup = {
/** The group label, in `type-label` caps. */
label: string;
items: AutocompleteOption[];
}AutocompleteProps
Props for Autocomplete: Base UI Autocomplete.Root props plus the suggestions, rows and color axes.
type AutocompleteProps = {
/** The suggestions, or titled groups. Pass `filter={null}` when the server filters them. */
items?: AutocompleteItems;
/** The input's placeholder, ending in "…"; never the label. */
placeholder?: string;
/** A leading icon in the box, such as `search` (inline tier). */
icon?:
| 'search'
| 'arrow_forward'
| 'arrow_upward'
| 'expand_more'
| 'close'
| 'remove'
| 'add'
| 'check'
| 'circle'
| 'chevron_right'
| 'chevron_left'
| 'menu'
| 'more_horiz'
| 'more_vert'
| 'play_arrow'
| 'pause'
| 'download'
| 'zoom_in'
| 'zoom_out'
| 'recenter'
| 'help'
| 'mail'
| 'content_copy'
| 'link'
| 'open_in_new'
| 'restart_alt'
| 'description'
| 'widgets'
| 'deployed_code'
| 'format_h2'
| 'format_h3';
/** Shows the chevron that opens the full list. Default `false`. */
showTrigger?: boolean;
/** The empty row. Default "No matches for '[query]'". Keep what the user typed. */
emptyText?: (query: string) => React.ReactNode;
/** Shows the loading row ("Searching…") while suggestions load. */
loading?: boolean;
/** The loading row's words. Default "Searching…". */
loadingText?: React.ReactNode;
/** A fetch failure, shown with the danger glyph instead of silently closing. */
error?: React.ReactNode;
/** The clear ×'s accessible name. Default "Clear". */
clearLabel?: string;
/** The chevron's accessible name. Default "Show suggestions". */
triggerLabel?: string;
/** Names the input when no visible label exists. Prefer a `FieldLabel`. */
'aria-label'?: string;
/** Class names for the box, added after the module's own. */
className?: string;
/** The box face becomes a nested `white` scope; patterned grounds only (§10.1). */
plate?: boolean;
/** Primary Radix scale: edge, value, icons and focus ring. Never defaulted [D133]. */
primary?:
| 'olive'
| 'sage'
| 'slate'
| 'sand'
| 'gray'
| 'mauve'
| 'brown'
| 'bronze'
| 'gold'
| 'red'
| 'ruby'
| 'crimson'
| 'tomato'
| 'pink'
| 'plum'
| 'indigo'
| 'iris'
| 'violet'
| 'purple'
| null;
/** Secondary Radix scale. Unused at rest; the danger scale while invalid. */
secondary?:
| 'olive'
| 'sage'
| 'slate'
| 'sand'
| 'gray'
| 'mauve'
| 'brown'
| 'bronze'
| 'gold'
| 'red'
| 'ruby'
| 'crimson'
| 'tomato'
| 'pink'
| 'plum'
| 'indigo'
| 'iris'
| 'violet'
| 'purple'
| 'amber'
| 'blue'
| 'cyan'
| 'grass'
| 'green'
| 'jade'
| 'lime'
| 'mint'
| 'orange'
| 'sky'
| 'teal'
| 'yellow'
| null;
/**
* The outline morph: the box's focus ring grows into the popup's frame as
* it opens and shrinks back onto the ring as it closes. Opens you ask for
* (the chevron with `showTrigger`, the arrow keys) and the first open
* after focus arrives morph; later opens and closes caused by typing are
* instant.
* Instant under reduced motion; off in forced colors and print, and
* wherever `--fgd-outline-morph: none` applies. Default `true`; `false`
* opens and closes the popup at once.
*/
morph?: boolean;
}Specification: DESIGN-SYSTEM.md §10.6 (combobox and autocomplete).