Autocomplete

CSS-first suggestion surfaces with a working local combobox example and native datalist alternative

Autocomplete

Core styles the input, suggestion surface and selection states. Applications own filtering, opening, keyboard navigation, selection and asynchronous data. No Core runtime is installed. For simple browser-owned suggestions, use the native datalist alternative below.

Imports

@import "@duskmoon-dev/core/base.css";
@import "@duskmoon-dev/core/themes/sunshine";
@import "@duskmoon-dev/core/components/autocomplete.css";
@import "@duskmoon-dev/core/components/form-group.css";
@import "@duskmoon-dev/core/components/button.css";

Aggregate: @duskmoon-dev/core; no-Tailwind: @duskmoon-dev/core/standalone.css. The extensionless components/autocomplete entry exports generated css and constructable styles. Individual imports need base.css and a theme. Use Moonlight for dark forms.

Basic Usage

This runnable single-input example includes its local application controller in the copyable code. It accepts free text as well as suggestions and submits one country value. Suggestions are local: there is no network request or implicit async search engine.

Basic Autocomplete

Focus stays on the input while arrows move the active suggestion; Enter accepts it, Escape dismisses the surface, and Tab leaves the field normally. Home/End retain native caret behavior. Disabled suggestions are not selectable. Reset restores the native default value and closes the surface after the browser’s reset action. Without the example script, this remains an ordinary text field but has no custom suggestion interaction.

Native Suggestions

A native list/datalist needs no controller. The browser owns filtering, popup positioning and keyboard behavior; the suggestion menu itself cannot be styled by Core. Suggestions do not restrict the submitted value. Use a native Select when values must come from a fixed list.

Native city suggestions

Disabled Fields

Use actual disabled attributes or a genuinely disabled fieldset. Visual classes alone do not disable interaction or submission. An application should close an open custom popup when disabling its control dynamically.

Disabled fieldset

Unavailable selection

Canonical Classes And Compatibility

Canonical API Retained aliases / presentation
.autocomplete, .autocomplete-input Container and native text field
.autocomplete-input-wrapper, .autocomplete-toggle Input-relative suggestion button
.autocomplete-open on root .autocomplete-dropdown-open or .show on dropdown
.autocomplete-dropdown, .autocomplete-options Popup surface and reset list layout
.autocomplete-option[aria-selected="true"] .selected, .autocomplete-option-selected
.highlighted .autocomplete-option-focused; application owns active descendant
.autocomplete-option[aria-disabled="true"] .disabled; application prevents selection
.autocomplete-group-header .autocomplete-group-label
.autocomplete-no-results .autocomplete-no-options
.autocomplete-tags, .autocomplete-tag, .autocomplete-tag-remove .autocomplete-chips, .autocomplete-chip, .autocomplete-chip-remove
.autocomplete-clear, .autocomplete-clearable Appearance only; application clears value
.autocomplete-loading, .autocomplete-highlight Application loading and match presentation
.autocomplete-sm/lg, .autocomplete-outlined/ghost Size and appearance
.autocomplete-{color} primary, secondary, tertiary, info, success, warning, error, accent, neutral, base

Multiple selection, removable tags, asynchronous requests, cancellation, debounce, virtualization and selection/value mapping need an application or framework adapter. Existing tag styles remain available; Core does not imply a multi-select or fetching engine. Use unique demo--prefixed IDs in docs, and unique IDs per instance in an application. The inline script is scoped to this example, not a global initializer for every .autocomplete.