Autocomplete
Searchable combobox for local or remote items with customizable list rows.
Attributes
| Name | Type | Default | Description |
|---|---|---|---|
value | string | — | Current input text and form value. A selection replaces it only when selectionBehavior is replace. |
name | string | — | Input name used for form submission. |
placeholder | string | — | Text shown while the input is empty. |
aria-label | string | null | null | Accessible name forwarded to the combobox input and composed list. |
suggestions | unknown[] | [] | Local items to search. An array in the property, JSON in the attribute; items may have any structure. |
item-key | string | — | Field used as a result's stable value. An empty value falls back to a primitive item or its index. |
label-field | string | — | Field used as primary row text. Defaults to label, name, title or value. |
description-field | string | — | Field used for the optional secondary row line. |
disabled-field | string | — | Field whose truthy value makes a row unavailable. |
search-fields | string[] | [] | Fields used by local matching; a ;-separated attribute or string array property. Defaults to every scalar field. |
selection-behavior | AutocompleteSelectionBehavior | replace | Whether selection preserves the typed query or replaces it with the selected item's key. |
debounce | number | 200 | Delay before calling dataSource, in milliseconds. |
min-query-length | number | 1 | Query length required before results are shown or requested. |
max-results | number | 20 | Maximum number of results shown after filtering or loading. |
show-empty | boolean | false | Keep the result panel open to show an empty state when nothing matches. |
readonly | boolean | false | Shows the value without allowing edits or opening suggestions. |
disabled | boolean | false | Disables the control and excludes it from form submission. |
required | boolean | false | Marks the control required for native form validation. |
open | boolean | false | Whether the suggestion panel is open. May also be controlled programmatically. |
Slots
| Name | Description |
|---|---|
prefix-icon | Icon or adornment shown before the text input. |
suffix-icon | Icon or adornment shown after the clear button. |
clear-icon | Replaces the default cross in the clear button. |
header | Content above the suggestion list, such as filter chips or a result summary. |
footer | Content below the suggestion list, such as an “all results” action. |
loading | Replaces the loading message inside the list. |
empty | Replaces the empty-result message inside the list. |
error | Replaces the remote-source error message inside the list. |
Events
| Name | Type | Description |
|---|---|---|
suggestion-select | CustomEvent<AutocompleteSelectEventDetail> | Fired after a row is chosen. The detail contains the selected key, original item and visible index. |
input | InputEvent | Re-dispatched from the inner input on every edit; also fired after a suggestion replaces the value. |
change | Event | Fired after the typed value is committed or a suggestion replaces it. |
query-change | CustomEvent<{ query: string }> | Fired on every user edit, before local filtering or a remote request. |
CSS custom properties
Grouped by semantic target and state from --c2-component__target__state--property. Click a group to collapse it; click a name to copy it.
| Name | Type | Default | Description |
|---|---|---|---|
--c2-autocomplete--min-height | pixel | 40px | |
--c2-autocomplete--padding | padding | 8px 10px | |
--c2-autocomplete--gap | pixel | 8px | |
--c2-autocomplete--background | color | #ffffff | |
--c2-autocomplete--color | color | #18181b | |
--c2-autocomplete--font-size | font-size | 14px | |
--c2-autocomplete--border | border | 1px solid #bcbcc6 | |
--c2-autocomplete--border-radius | border-radius | 8px | |
--c2-autocomplete__hover--border | border | 1px solid #a1a1aa | |
--c2-autocomplete__focus--border | border | 1px solid rgb(2, 101, 220) | |
--c2-autocomplete__focus--outline | outline | none | |
--c2-autocomplete__placeholder--color | color | #71717a | |
--c2-autocomplete__disabled--opacity | opacity | 0.38 | |
--c2-autocomplete__icon--size | pixel | 18px | |
--c2-autocomplete__icon--color | color | #71717a | |
--c2-autocomplete__panel--background | color | #ffffff | |
--c2-autocomplete__panel--border | border | 1px solid #e4e4e7 | |
--c2-autocomplete__panel--border-radius | border-radius | 8px | |
--c2-autocomplete__panel--box-shadow | box-shadow | 0 12px 32px rgba(24, 24, 27, 0.14) | |
--c2-autocomplete__panel--max-height | pixel | 320px | |
--c2-autocomplete__list--padding | padding | 4px | |
--c2-autocomplete__header--background | color | transparent | |
--c2-autocomplete__header--color | color | #71717a | |
--c2-autocomplete__header--padding | padding | 10px 12px | |
--c2-autocomplete__header--border-bottom | border | 1px solid #e4e4e7 | |
--c2-autocomplete__footer--background | color | transparent | |
--c2-autocomplete__footer--color | color | #71717a | |
--c2-autocomplete__footer--padding | padding | 10px 12px | |
--c2-autocomplete__footer--border-top | border | 1px solid #e4e4e7 | |
--c2-autocomplete__option--min-height | pixel | 44px | |
--c2-autocomplete__option--padding-top | pixel | 8px | |
--c2-autocomplete__option--padding-right | pixel | 10px | |
--c2-autocomplete__option--padding-bottom | pixel | 8px | |
--c2-autocomplete__option--padding-left | pixel | 10px | |
--c2-autocomplete__option--gap | pixel | 10px | |
--c2-autocomplete__option--border-radius | border-radius | 6px | |
--c2-autocomplete__option__active--background | color | #f4f4f5 | |
--c2-autocomplete__option__active--color | color | #18181b | |
--c2-autocomplete__description--color | color | #71717a | |
--c2-autocomplete__description--font-size | font-size | 12px | |
--c2-autocomplete__highlight--color | color | rgb(2, 101, 220) | |
--c2-autocomplete__highlight--font-weight | font-weight | 600 | |
--c2-autocomplete__status--color | color | #71717a | |
--c2-autocomplete__status--padding | padding | 14px 12px | |