AntaInputAutocomplete
Switch to dark theme
Search documentation
On this page

Input with autocomplete (combobox) Documentation has not yet been reviewed by a human.

InputAutocomplete offers suggestions while people enter text. Use it for package names, search queries, or other fields where common entries help but people can also enter their own value. Choosing a suggestion fills the field with its value. Use Select when an option’s identity is the value.

Give the field a visible label. If you omit it, provide aria-label or aria-labelledby. A placeholder alone does not name the field.

Playground

Free text is the point

The field keeps whatever someone types, including text absent from the list. onValueChange reports that text as it changes. Use onSelect when the application also needs to know that someone chose a suggestion.

ReactPreactSolidSvelteVueAngularQwikLitAstro
Value: (empty)
const frameworks = ['React', 'Preact', 'Solid', 'Svelte', 'Vue', 'Angular', 'Qwik', 'Lit', 'Astro']
const [value, setValue] = useState('')
<InputAutocomplete
label="Framework"
placeholder="Type to search…"
clearable
suggestions={frameworks}
value={value}
onValueChange={setValue}
/>
<div>Value: <code>{value || '(empty)'}</code></div>

Suggestions

Use strings for a simple list, or option objects to show a readable label, a supporting hint, or an icon. Choosing a row fills the field with its value, so the Anta suggestion here fills in @antadesign/anta. Disabled suggestions remain visible and are skipped during keyboard navigation.

AntaUI componentsPlotCanvas chartsStickersIllustrationsArchivedUnavailable
<InputAutocomplete
label="Package"
hint="Choose a package name or enter another."
suggestions={[
{ value: '@antadesign/anta', label: 'Anta', hint: 'UI components', icon: 'cube' },
{ value: '@antadesign/plot', label: 'Plot', hint: 'Canvas charts', icon: 'workflow' },
{ value: '@antadesign/stickers', label: 'Stickers', hint: 'Illustrations', icon: 'asterisk' },
{ value: '@antadesign/archived', label: 'Archived', hint: 'Unavailable', disabled: true },
]}
/>

Managing the value

Pass value and update it through onValueChange when another part of your application needs the text. Reset controlled text with ''. For a field that keeps its own text, use defaultValue; a form reset restores that default without opening an unfocused field’s suggestions or moving focus.

ReactPreactReset text
const [value, setValue] = useState('React')
<InputAutocomplete label="Framework" suggestions={frameworks}
value={value} onValueChange={setValue} clearable />
<Button label="Reset text" onClick={() => setValue('')} />

Filtering

The built-in filter matches the value, label, and hint without case sensitivity, and highlights matching label and hint text. Use a function when your application needs a different rule, such as matching word prefixes. It receives the original field text, including whitespace; decide whether to trim it in your matcher.

ReactPreactSolidSvelteVueAngularQwikLitAstro
<InputAutocomplete
label="Framework prefix"
suggestions={frameworks}
filter={(option, query) => option.value.toLowerCase().startsWith(query.trim().toLowerCase())}
/>

Application-provided results

Pass filter={false} when your application already selects or ranks the suggestions. This preserves their order and skips local highlighting. The example supplies matching projects in reverse order; fetched results use the same pattern.

Customer portalBuild toolsBilling dashboardBilling service
const projects = ['Billing service', 'Billing dashboard', 'Build tools', 'Customer portal']
const [value, setValue] = useState('')
const results = projects.filter(name => name.toLowerCase().includes(value.toLowerCase())).reverse()
<InputAutocomplete
label="Project"
hint="Results use the application's order. You can also enter a new project."
suggestions={results}
filter={false}
value={value}
onValueChange={setValue}
/>

Replace suggestions as results arrive. New results update an open list; they do not reopen it after Escape or focus loss. Your application owns loading, request cancellation, and discarding responses for older queries.

Keyboard interaction

Typing leaves every suggestion inactive, so Enter keeps the typed text and closes the list. Arrow Down highlights the first enabled suggestion; Arrow Up and Arrow Down move through the list. Enter on an active suggestion fills the field. Editing again clears that active suggestion. Input-method composition keeps its own candidate navigation and confirmation keys.

Escape closes the list and keeps focus in the field. Tab closes it and moves to the next control. Selecting a suggestion or clicking the list’s padding keeps focus in the field. Clicking within an open field leaves the list open while placing the caret. The field exposes combobox semantics, the popup is a listbox, and the active suggestion is associated directly with the focused input.

Events

Use onValueChange for application text state. onInput, onFocus, onBlur, and onKeyDown also receive their field events. An input event reports an edit that already happened; preventDefault() does not reject the text.

A consumer onKeyDown can prevent the wrapper’s plain-Enter dismissal. Menu handles active suggestions and navigation earlier in document capture. Those actions cannot be canceled from the field callback, and Escape is consumed before it reaches the field. See the callback reference for ordering.

Component props

Prop Type Default Description
suggestions stringSelectOption[] — The suggestions: bare strings or SelectOptions (value / label / hint / icon / tone / disabled). A flat list; picking one fills the field.
value? string — The controlled field text. Any string is valid, including '' for an empty field. Omit or pass undefined for uncontrolled use. Parent updates do not call onValueChange. Releasing control retains the latest controlled text.
defaultValue? string — Initial uncontrolled text and the value restored by a form reset. Resetting an unfocused field does not open suggestions or move focus.
onValueChange? (value) => void — Reports text changes from typing, picking a suggestion, clearing, or form reset.
onSelect? (option) => void — Fires after onValueChange when a suggestion is chosen, with the normalized option. This reports the choice even if a controlled parent rejects the value. Typing and clearing do not call it.
filter? boolean(option, query) => boolean true How suggestions match the text. true uses the built-in case-insensitive substring match on value / label / hint; a function (option, query) => boolean receives the original field text, including whitespace, once per option on each render, including when empty. Custom matching has no automatic highlighting. false shows suggestions unchanged for application-provided async or remote filtering, without automatic highlighting. Replacing results updates an open list but does not reopen a dismissed list.
placeholder? string — Placeholder text.
size? smallmediumlarge medium Field size.
status? neutralbrandinfosuccesswarningcritical — Validation status.
statusIcon? stringfalseIconShape — Status icon override, or false to drop it.
tone? string — Custom accent color — a named tone or any CSS color.
clearable? boolean — Show a clear button while the field has text.
name? string — Form field name.
disabled? boolean — Disable the field.
label? ReactNode — Field label.
hint? ReactNode — Hint under the field.
leading? ReactNode — Leading adornment inside the field.
trailing? ReactNode — Trailing adornment inside the field.
onFocus? (event) => void — Observe focus before the suggestion list opens.
onBlur? (event) => void — Observe focus loss. The suggestion list closes without changing the text.
onInput? (event) => void — Observe editing before onValueChange. The input event reports text that has already changed; preventDefault() does not reject that text.
onKeyDown? (event) => void — Observe keys before the wrapper's plain-Enter dismissal. preventDefault() keeps that dismissal from running. Menu handles navigation and active-option activation earlier, in document capture; this callback cannot veto those actions. Composing keys remain with the input method.
Inherited props (className, id, slot, style, tabIndex, title)
Prop Type Default Description
className? string — CSS class on the component's root element (merged with the component's own classes). Use it directly for layout and positioning — grid/flex placement, margins, alignment — rather than wrapping the component in a <div>/<span>.
id? string — HTML id attribute.
slot? string — Assigns the element to a named <slot> of a parent web component (e.g. slot="header" inside a <Dialog>, slot="footer" inside a <Dialog>).
style? CSSProperties — Inline styles on the component's root element. Set layout/positioning here (or via className) directly on the component instead of adding a wrapper.
tabIndex? number — Tab order. Set to -1 to skip the element when tabbing.
title? string — HTML title attribute — native browser tooltip on hover.

Plus every standard DOM event handler (onClick, onFocus, onKeyDown, …) and any data-* or aria-* attribute — forwarded as-is to the underlying <a-*> element.

Web Component

InputAutocomplete composes Input and Menu. It has no a-input-autocomplete element or registration entry. Raw authors own the text, filtering, popup state, and equivalent ARIA declarations. See Install and configure for imports, renderer setup, and CSP guidance.

Native HTML input with autocomplete

For browser-native suggestions, pair a native input with a datalist. The browser supplies the popup and keeps free-form entry. Use InputAutocomplete when you need Anta’s suggestion rows and popup styling.

<label for="autocomplete-people">Person</label>
<input id="autocomplete-people" data-anta type="text" list="people" placeholder="Search people">
<datalist id="people">
<option value="Maya Chen">
<option value="Noah Williams">
<option value="Olivia Martinez">
<option value="Liam Johnson">
</datalist>

Styling

Use Input’s size, status, tone, and adornment props to configure the field. className and style apply to its a-input. Target Input’s parts for field styles and the adjacent Menu’s ::part(menu) for the suggestion popup. Option objects accept className, style, and application data attributes on their rows.

The package-field class below belongs to this example. Replace it with your own selector.

AntaUI componentsPlotCanvas chartsStickersIllustrationsArchivedUnavailable
<InputAutocomplete className="package-field" label="Package" suggestions={packages} tone="info" />
.package-field { width: 260px; }
.package-field::part(field) { border-radius: 12px; }
.package-field + a-menu::part(menu) { border-radius: 12px; }