Skip to main content
Neural UIv2.0.0Documentation
View v1 GitHub

Autocomplete

Suggest destinations while the user types, with strict selection or free text.

Category
Forms and selection
Import
@neural-ui/core/autocomplete
Selector
neu-autocomplete
import { NeuAutocompleteComponent } from '@neural-ui/core/autocomplete';

Usage

Autocomplete separates typed query text from the selected value. In strict mode the user selects an available suggestion; free-text mode also accepts text that is not in the collection.

The example handles queryChange synchronously and supplies matching suggestions. For remote data, handle suggestionsRequest and provide the response through suggestions; query text is not itself a confirmed selection.

Signal Forms

Bind FormField to the value-owning control and add required to the form schema. Select a destination, leave the field to mark it touched, and reset it to check both value and validation state. A required marker on its own does not validate your form.

Signal Forms guide

Signal Forms

Value: โ€” ยท Valid: false

Try and configure

Change the settings below and interact with the live control. The preview, current application value and generated template stay together. A disabled destination lets you check that unavailable choices cannot be selected.

Try and configure
Live preview

Generated template: reflects the settings above. Imports and state are in the Code tab.

template.html
<neu-autocomplete
  [options]="destinations"
  [suggestions]="suggestions()"
  (queryChange)="query.set($event)"
  (suggestionsRequest)="refreshSuggestions($event.query)"
  [(value)]="destination"
  [dropdown]="true"
  [clearAriaLabel]="'Clear selection'"
  [delay]="0"
  [dropdownAriaLabel]="'Show destinations'"
  [emptyLabel]="'No matches'"
  [floatingLabel]="true"
  [fluid]="true"
  [label]="'Destination'"
  [listAriaLabel]="'Destination'"
  [loadingLabel]="'Loading destinations'"
  [placeholder]="'Choose a destination'"
/>

Value and events

Use one source of truth: [(value)]="destination" or [value]="destination()" with (valueChange)="destination.set($event)". Do not bind both forms at once.

Inputs configure the control. valueChange synchronizes its model; the other Outputs report their documented actions or lifecycle. Requests for suggestions, children or remote windows require the application to supply data.

Accessibility and keyboard

Use a visible label or an accessible name. Test keyboard navigation, disabled options, selection and closing the panel. Custom option templates should keep descriptive text and must not introduce a nested button or another focusable checkbox inside the option.

Key
Action
Tab Moves focus into or out of the control.
ArrowDown / ArrowUp Moves the active option through available options.
Enter Activates the focused option.
Escape Closes the panel without selecting another option.

API

The reference lists the public Inputs, models, Outputs and Templates from the pinned Core package. Click a named type to open its definition. Each applicable Template has an executable example and its actual source.

Inputs

Configure the component with [property]="value". Your application supplies these values; the component does not replace the state you pass in.

Name
Type
Default
Template binding
Description
ariaDescribedBystring | nullnull[ariaDescribedBy]IDs of elements describing the control, separated by spaces.
ariaLabelstring | nullnull[ariaLabel]Accessible name when no visible label is available.
ariaLabelledBystring | nullnull[ariaLabelledBy]ID of the element that supplies the accessible name.
autocompletestring'off'[autocomplete]Native browser autocomplete attribute for the input.
autofocusbooleanfalse[autofocus]Requests focus when the control is initialized.
autoHighlightbooleanfalse[autoHighlight]Automatically highlights the first available suggestion.
autoOptionFocusbooleanfalse[autoOptionFocus]Moves the active option to an available option when the list opens.
clearablebooleantrue[clearable]Shows a clear action when a value is selected.
clearAriaLabelstring'Clear value'[clearAriaLabel]Accessible name of the clear-selection button.
compareWith(left: V, right: V) => booleanObject.isDerived default[compareWith]Comparison function for selected values; use stable domain identity.
completeOnFocusbooleanfalse[completeOnFocus]Requests suggestions when the input receives focus.
dataFirstnumber0[dataFirst]Logical index of the first loaded option in a remote window.
delaynumber300[delay]Debounce time in milliseconds before requesting suggestions.
dirtybooleanfalse[dirty]Form state indicating that the user has changed the value.
disabledbooleanfalse[disabled]Disables user interaction; disabled options cannot be selected.
dropdownbooleanfalse[dropdown]Shows a button that opens or requests suggestions.
dropdownAriaLabelstring'Show suggestions'[dropdownAriaLabel]Accessible name of the suggestions button.
dropdownModeNeuAutocompleteDropdownMode'blank'[dropdownMode]Uses the current query or an empty query for dropdown requests.
emptyLabelstring'No results'[emptyLabel]Message displayed when there are no available options.
emptySelectionMessagestring'No selected item'[emptySelectionMessage]Announcement when no option is selected.
errorMessagestring''[errorMessage]Visible error message associated with the field.
errorsreadonly ValidationError.WithOptionalFieldTree[][][errors]Validation errors supplied by the form or the application.
filterConfigReadonly<NeuOptionFilterConfig<T>>{}[filterConfig]Fields, matching mode, locale and client/server filtering strategy.
floatingLabelbooleanfalse[floatingLabel]Displays the label in the floating-label field style.
fluidbooleanfalse[fluid]Makes the control fill its containing width.
focusOnHoverbooleantrue[focusOnHover]Changes the active option when the pointer enters an option.
groupConfigNeuOptionGroupConfig<T, G> | nullnull[groupConfig]Accessors used to read group labels, children and disabled state.
groupsreadonly G[][][groups]Grouped options, with child items configured through groupConfig.
groupSuggestionsreadonly G[] | nullnull[groupSuggestions]Enables grouped suggestion rendering.
hiddenbooleanfalse[hidden]Hides the control according to the form state.
hintstring''[hint]Help text associated with the field.
idstring | nullnull[id]Identifier of the control host.
inputIdstring | nullnull[inputId]Identifier of the native input for label and accessibility associations.
inputSizenumber | nullnull[inputSize]Native input size attribute, independent of the visual size variant.
invalidbooleanfalse[invalid]Displays the invalid state; it does not add a validation rule.
labelstring''[label]Visible field or option label.
lazybooleanfalse[lazy]Uses loaded windows and emits requests for missing option data.
listAriaLabelstring'Suggestions'[listAriaLabel]Accessible name of the suggestions list.
loadingbooleanfalse[loading]Displays the loading state while the application supplies data.
loadingLabelstring'Loading...'[loadingLabel]Message or announcement for loading options.
maxLengthnumber | undefinedundefined[maxLength]Maximum native text input length.
minLengthnumber | undefinedundefined[minLength]Minimum native text input length.
minQueryLengthnumber0[minQueryLength]Minimum query length before requesting suggestions.
modeF'strict' as FDerived default[mode]strict selects an available suggestion; free-text also accepts arbitrary text.
namestring''[name]Name associated with the native form control.
optionDisabledNeuOptionDisabledAccessor<T> | nullnull[optionDisabled]Field name or function that marks an option as disabled.
optionLabelNeuOptionLabelAccessor<T> | nullnull[optionLabel]Field name or function used to obtain the visible option label.
optionsreadonly T[][][options]Loaded option records. Accessors allow using your own domain objects.
optionValueNeuOptionValueAccessor<T, V> | nullnull[optionValue]Field name or function used to obtain the stored option value.
patternreadonly RegExp[][][pattern]Native pattern attribute for text input.
pendingbooleanfalse[pending]Form state indicating that asynchronous validation is pending.
placeholderstring''[placeholder]Text shown when the field has no selected value.
readonlybooleanfalse[readonly]Keeps the value readable without allowing the user to change it.
requiredbooleanfalse[required]Marks the field as required; use a form validator to enforce it.
scrollHeightstring'240px'[scrollHeight]Maximum height of the option viewport.
searchMessagestring | nullnull[searchMessage]Accessible announcement describing the search result count.
selectionMessagestring'{0} item selected'[selectionMessage]Accessible announcement describing the selected option.
selectOnFocusbooleanfalse[selectOnFocus]Selects the option as focus moves, rather than waiting for activation.
showEmptyMessagebooleantrue[showEmptyMessage]Shows the empty-suggestions message.
sizeNeuAutocompleteSize'md'[size]Visual field size: sm, md or lg.
suggestionsreadonly T[] | nullnull[suggestions]Suggestion records supplied for the current query.
tabindexnumber0[tabindex]Tab order of the keyboard entry point.
totalItemsnumber | nullnull[totalItems]Logical total option count for remote windows.
touchedbooleanfalse[touched]Form state indicating that the control has been visited.
typestring'text'[type]Native text input type.
variantNeuAutocompleteVariant'outline'[variant]Visual field variant: outline or solid.
virtualScrollbooleanfalse[virtualScroll]Renders an option window instead of every option.
virtualScrollBuffernumber3[virtualScrollBuffer]Extra options rendered before and after the visible virtual window.
virtualScrollItemSizenumber | nullnull[virtualScrollItemSize]Measured option row height in pixels for virtual scrolling.
virtualScrollVisibleItemsnumber8[virtualScrollVisibleItems]Number of visible virtual rows.

Models

A model supports [(property)]="signal" or the [property] and (propertyChange) pair. Choose one form, not both.

Name
Type
Default
Template binding
Description
valueNeuAutocompleteValue<V, F>null as NeuAutocompleteValue<V, F>Derived default[(value)]Confirmed value or null; free-text mode also accepts a string. queryChange carries search text.

Outputs

Listen to an event with (event)="handler($event)". The table explains the data your handler receives and how to use it.

Name
Payload
Template binding
Description
clearedNeuAutocompleteClearEvent<V, F>(cleared)="onCleared($event)"Emitted for the explicit clear action; valueChange carries the resulting value.
closedvoid(closed)="onClosed($event)"Emitted after the browser panel closes.
dropdownClickNeuAutocompleteDropdownClickEvent(dropdownClick)="onDropdownClick($event)"Describes the query and source of the suggestions-button action.
focusEnteredFocusEvent(focusEntered)="onFocusEntered($event)"Emitted when focus enters the control.
focusLeftFocusEvent(focusLeft)="onFocusLeft($event)"Emitted when focus leaves the control.
inputKeydownKeyboardEvent(inputKeydown)="onInputKeydown($event)"Native keydown event from the text input.
keyUpKeyboardEvent(keyUp)="onKeyUp($event)"Native keyup event from the text input.
openedvoid(opened)="onOpened($event)"Emitted after the browser panel opens.
optionActivatedNeuOptionActivatedEvent<T, V>(optionActivated)="onOptionActivated($event)"Activated option, its value and the originating event.
queryChangestring(queryChange)="onQueryChange($event)"Current text query, distinct from the selected value.
suggestionsRequestNeuAutocompleteSuggestionsRequest(suggestionsRequest)="onSuggestionsRequest($event)"Requests suggestions with query and request identity; the application supplies suggestions.
touchvoid(touch)="onTouch($event)"Notifies the form that the control has been touched; not a value change.

Templates

ng-content projects content into the component. TemplateRef inputs receive a template; ng-template directives identify templates with a typed context. A directive shared by an entrypoint is not necessarily a slot of this component.

Name
Mechanism
Contract
NeuAutocompleteClearIconDirectiveView example Public template directive (entrypoint)ng-template[neuAutocompleteClearIcon]
NeuAutocompleteDropdownIconDirectiveView example Public template directive (entrypoint)ng-template[neuAutocompleteDropdownIcon]
NeuAutocompleteEmptyDirectiveView example Public template directive (entrypoint)ng-template[neuAutocompleteEmpty]
NeuAutocompleteFooterDirectiveView example Public template directive (entrypoint)ng-template[neuAutocompleteFooter]
NeuAutocompleteGroupDirectiveView example Public template directive (entrypoint)ng-template[neuAutocompleteGroup]
NeuAutocompleteHeaderDirectiveView example Public template directive (entrypoint)ng-template[neuAutocompleteHeader]
NeuAutocompleteItemDirectiveView example Public template directive (entrypoint)ng-template[neuAutocompleteItem]
NeuAutocompleteLoaderDirectiveView example Public template directive (entrypoint)ng-template[neuAutocompleteLoader]
NeuAutocompleteLoadingIconDirectiveView example Public template directive (entrypoint)ng-template[neuAutocompleteLoadingIcon]

Each example demonstrates a different template. Switch between Demo and Code to inspect its implementation, imports and state.

ClearIcon template

NeuAutocompleteClearIconDirective

ClearIcon template

Use the dropdown button or type to open the suggestions.

DropdownIcon template

NeuAutocompleteDropdownIconDirective

DropdownIcon template

Use the dropdown button or type to open the suggestions.

Empty template

NeuAutocompleteEmptyDirective

Empty template

Open the control to see the empty state.

Group template

NeuAutocompleteGroupDirective

Group template

Use the dropdown button or type to open the suggestions.

Header template

NeuAutocompleteHeaderDirective

Header template

Use the dropdown button or type to open the suggestions.

Item template

NeuAutocompleteItemDirective

Item template

Use the dropdown button or type to open the suggestions.

Loader template

NeuAutocompleteLoaderDirective

Loader template

Use the dropdown button or type to open the suggestions.

LoadingIcon template

NeuAutocompleteLoadingIconDirective

LoadingIcon template

Use the dropdown button or type to open the suggestions.

Public methods

Name
Contract
clearclear(originalEvent?: Event | null, reason?: 'button' | 'force-selection' | 'programmatic'): void;
closeclose(originalEvent?: Event | null, reason?: OverlayReason, restoreFocus?: boolean): void;
focusfocus(): void;
openopen(originalEvent?: Event | null, reason?: OverlayReason): void;
openAllopenAll(event?: Event | null): void;
resetreset(): void;
selectOptionselectOption(option: T, originalEvent?: Event | null): void;

Public Types

Open a type to inspect its definition and interface fields.

Styles and tokens

Load Core styles once. Use the public tokens below for local customization or a preset for application-wide changes. Keep labels, focus, selected options and disabled states readable in both light and dark themes.

Specific tokens

Token
Purpose
State / variant
Default / source
Fallback
--neu-autocomplete-option-height Inherited theme value used by this component Field surface 40pxRoot declarationNo token alias

Shared tokens used

Override these on a local wrapper to affect this example. An override on :root affects other components that use the same token.

Token
Purpose here
Other impact
Default / fallback
--neu-border Normal control and cell borders Shared by other Core consumers; scope the override. rgba(15, 23, 42, 0.08)
--neu-border-hover Control borders on hover Shared by other Core consumers; scope the override. rgba(15, 23, 42, 0.16)
--neu-error Invalid field or danger-action color Shared by other Core consumers; scope the override. #dc2626
--neu-focus-ring Normal keyboard-focus ring Shared by other Core consumers; scope the override. 0 0 0 var(--neu-focus-ring-width) rgba(0, 122, 255, 0.15)
--neu-primary Brand color for active controls and emphasis Shared by other Core consumers; scope the override. #007aff
--neu-primary-50 Subtle brand surface for hover and focus states Shared by other Core consumers; scope the override. #eff6ff
--neu-primary-dark Dark brand shade; outline and ghost Button text in the light theme Shared by other Core consumers; scope the override. #005fcc
--neu-radius Control corner radius Shared by other Core consumers; scope the override. 8px