Skip to content

AutoComplete ​

Type to get suggestions: the value is free text (browser address bar / datalist mental model) — the suggestion list only aids input. Keyboard selection, grouping, debounced remote suggestions, and custom rendering are supported.

Boundary vs. Select(searchable) / Combobox

ComponentValue sourceInput formBest for
oas-auto-completeAny free text; suggestions are shortcutsInput is the controlSearch-box suggestions, email completion, free-form tags
oas-select searchableMust come from the option setButton-triggered; search box appears when expandedConstrained choice (value must be valid)
oas-comboboxMust come from the option setInput is the control; typing only filtersAlways-visible-input constrained single select

When the value must be one of the options, use select(searchable) or combobox instead of trying to add "strict validation" to auto-complete; for multiple/tags scenarios use oas-select multiple or oas-dynamic-tags — auto-complete stays single-value free text.

Basic Usage ​

Basic usage

Typing auto-filters matching items in the dropdown; the first item is highlighted by default and Enter commits it directly; ↑/↓ move the highlight, Esc closes; blur does not clear the input (free text never falls back).

Preset Value ​

Preset value

Reading/writing the current value goes through the public value property (el.value to read, el.value = x to write, matching native input.value). Note the label / value split: this component's submission semantics are the visible text — after selecting a suggestion, el.value returns that suggestion's label (visible text), while the value attribute is the option.value (e.g. apple); oas-form's values snapshot reads the attribute (= option.value). The two are different layers — pick per need.

Clearable ​

Clearable

A clear button appears when the input has content; clicking clears the input and dispatches oas-clear and oas-change (empty value).

Remote Suggestions (debounce + loading) ​

Remote search suggestions

debounce (ms, default 0 = off) only debounces oas-input dispatching and filtering — the input display is never debounced; the host sets loading while requesting, the dropdown shows a loading placeholder, and refilling options renders the suggestions.

Show on Focus (trigger-on-focus) ​

Show all suggestions on focus (trigger-on-focus)

Off by default (popping the full list on focusing an empty input disturbs compact forms); enabling it follows the datalist mental model: focus shows suggestions filtered by the current input.

Grouped Suggestions ​

Groups (group)

Options with a group field render group titles (not selectable) with indented options; ↑/↓ navigate continuously across groups.

Large Datasets (virtual scrolling) ​

Virtual scrolling (1000 suggestions)

With virtual, the suggestion panel renders only the visible window (reusing oas-virtual-list window math with top/bottom padding holding the scroll height) — thousands of suggestions scroll smoothly and the panel height stays constant; item-height tunes the fixed row height (default 36). While navigating with ↑/↓ the window follows the highlighted item and aria-activedescendant keeps pointing at a visible row; options with group automatically fall back to full rendering (same contract as oas-select).

Custom Option Rendering ​

Custom option (oas-option-render event)

Custom option (template slot)

The dual channel matches oas-select: listen to oas-option-render (detail.element is the text container the host can rewrite into icons/rich text); or provide a static skeleton via <template slot="option"> whose [data-option-label] node auto-binds the option text.

Panel header/footer and empty slots

Hint: try a fruit nameView all fruits →Try another keyword

header / footer slots render at the top/bottom of the suggestion panel (hint bar, "view all" link); the empty slot replaces the default "no match" text.

Size & Status ​

Sizes (size)

Status (status)

size supports small / medium / large (follows the nearest oas-config-provider size injection); status supports success / warning / error (error syncs aria-invalid, drivable by oas-form-item validation).

Variant ​

Variant (variant)

variant aligns with the three oas-input variants: outlined (default) / filled (gray fill, border on hover) / borderless (no border, no focus shadow); invalid values fall back to outlined.

Focus Events (oas-focus / oas-blur) ​

focus / blur events

Focus/blur dispatch oas-focus / oas-blur with detail: { value } carrying the current input text, matching the oas-input event contract.

Readonly ​

Readonly

readonly allows focus & copy but no editing; focus and keyboard no longer open suggestions.

IME (Input Method Editor) ​

During IME composition (before confirming the candidate) the component does not filter, does not dispatch oas-input, and Enter never mis-selects a suggestion; after composition ends, one filtered update fires with the final text. Try typing Chinese in any demo on this page — no extra configuration needed.

Disabled ​

Disabled

No Match ​

Empty state

Events ​

Input & selection events

Listen to oas-input (typing, after debounce), oas-change (select or clear), oas-clear (clear):

required ​

required (native validation chain)

required drives the native validation chain (form-associated): when unfilled, checkValidity() returns false (valueMissing) and native form submission is blocked; it recovers to :valid once filled.

Programmatic read/write of the current value goes through the public value property (like the native input.value): el.value reads the current input text; el.value = x writes the controlled value attribute and immediately syncs the inner control (clearing the in-progress filter query) without dispatching events.

Panel placement ​

placement controls the suggestion panel placement in 12 directions (aligned with the floating-positioning engine; -start / -end are logical writing-direction semantics, mirrored automatically in RTL): flips along the main axis when space is short and avoids viewport edges. Default bottom-start (panel's start edge aligned with the input's start edge, opening downward); the actual placement (including flips) is written to the panel's data-placement.

placement=top-start (opens upward)

autofocus ​

autofocus is forwarded to the inner input (native autofocus doesn't pierce Shadow DOM): the component focuses once after mounting. Click the button below to mount a fresh autofocus instance and watch the caret land inside the input.

Focused on mount

Mount an autofocus input

API ​

oas-auto-complete ​

Attributes ​

AttributeDescriptionTypeDefault
autofocusFocuses the inner input after mountingboolean—
clearableClearable (shows a clear button when the input has content; clearing dispatches oas-clear and an empty oas-change)boolean—
debounceInput debounce (ms, default 0 = off): only debounces oas-input dispatch and filtering, never the input displaystring0
disabledDisabledboolean—
item-heightFixed virtual row height in px (with virtual, default 36)string36
loadingLoading placeholder (dropdown shows a loading state; remote-suggestion request state)boolean—
optionsOptions, JSON array [{ label, value, disabled?, group? }] (group is the group title)Option[] | string[]
placeholderPlaceholder textstring—
placement12-direction panel placement (engine flip/RTL result written to data-placement)stringbottom-start
readonlyReadonly (focusable & copyable, not editable; focus and keyboard never open suggestions)boolean—
requiredRequired marker (drives the native valueMissing validation chain; not passed through to the inner control)boolean—
sizeSize tier: small / medium / large (default medium, follows the nearest config-provider injection)stringmedium
statusValidation status: success / warning / error (error syncs aria-invalid, drivable by oas-form-item validation)string—
trigger-on-focusShow suggestions on focus (datalist mental model; off by default — input-first)boolean—
valuePreset valuestring—
variantVisual variant: outlined (default) / filled / borderless; invalid values fall back silentlystring—
virtualVirtual scrolling (renders only the visible window via oas-virtual-list; grouped options fall back to full rendering)boolean—

Property (JS property; see each row for attribute reflection) ​

PropertyDescriptionTypeDefault
valueCurrent value: the visible text (the selected suggestion label after choosing); the value attribute is the option.valuestring—

Events ​

EventDescription
oas-blurDispatched on blur with the current input text, detail: { value: this.input?.value ?? '' }
oas-changeSelected or cleared, detail: { value, label }
oas-clearClear button clicked, detail: { value } (value before clearing)
oas-focusDispatched on focus with the current input text, detail: { value: this.input?.value ?? '' }
oas-inputWhile typing (after debounce), detail: { value }
oas-option-renderDispatched after each option row renders, detail: { index, option, element }; the host can rewrite element (icons/rich text)

Slots ​

NameDescription
emptyCustom no-match empty state (replaces the default text)
footerSuggestion panel footer content (e.g. a view-all link)
headerSuggestion panel header content (e.g. a hint bar)
template[slot="option"]Custom option template skeleton; the [data-option-label] node auto-binds the option text

CSS Variables ​

CSS VariableDefault
--oas-auto-complete-dropdown-height240px
--oas-glass-blurnone
--oas-glass-ringtransparent

Keyboard: ↑/↓ to move (looping), Enter to select the highlighted item (first item highlighted by default), Esc to close.

Released under the MIT OR Apache-2.0 License.