Autocomplete

A text field that suggests matching options while the user types. Use it for long lists people search by name, filtered in the browser or fetched from a server.

  • vig-autocomplete
  • ng-template[vigSelectOption]
Import
import { Autocomplete } from '@vigdx/ui/autocomplete';
import { SelectOptionTemplate } from '@vigdx/ui/select';

Basic

Pass options and bind [(value)] ; the list narrows to labels containing the typed text. minQueryLength sets how many characters open the list ( 0 opens it on focus) and clearable adds a clear button. Text that matches no option reverts on blur.

Suggestions open on focus.

Destination: none · Origin: ist

With [localFilter]="false" the field shows options as given. Listen to searchRequest , which fires once typing pauses for debounce ms, load results into options and set loading meanwhile to show a spinner. queryChange is the undebounced counterpart: it emits the text on every keystroke, e.g. for a character counter; use searchRequest for requests.

Results come from a (simulated) server.

Value: none

Object values

Values can be objects. They are compared by reference, so the bound value must be one of the option instances. displayWith sets the text shown in the field for the selected value.

Assignee: [email protected]

Free text

allowCustom keeps typed text that matches no option as the value, so suggestions are optional. Use it with string values.

Pick a suggestion or keep your own text.

Value: none

Label, error, states and sizes

labelPosition="top" puts the label above the field and emptyMessage replaces the "no results" text. Errors show once the field is touched and invalid . size is sm , md (default) or lg .

Choose a city.

Reactive Forms

Import VigValueAccessor next to the component to use formControlName , [formControl] or ngModel .

{
  "from": "ams",
  "to": null
}

Signal Forms

vig-autocomplete implements FormValueControl<T | null> . Its query length input is called minQueryLength so that it does not clash with the minLength rule of Signal Forms.

Valid: no · Office: none

Styling hooks

Internal elements carry a stable data-part and the component's data-scope; both are public API, so removing one is a breaking change. Select a part by both, e.g. [data-scope="autocomplete"][data-part="field"] { … }: the pair stays within this component when kit components nest, and also reaches parts in overlay panels, which render outside the host. State is exposed through aria-* and, where listed, a data-state; literal values are checked by the API gate, values computed from the component's state follow its documented types. Other data-* attributes listed below (such as data-opening while an overlay animates) are API too. See Customizing.

Scope: [data-scope="autocomplete"]

Autocomplete styling hooks
Part Element data-state
field Positioned wrapper of the label and the control. —
label The visible (or floating) label. —
input The native <input> . —
hint The vig-hint (a display: contents host; style its text part). —
disabled-reason The vig-hint with the disabled reason ( display: contents ). —
error The vig-field-error (a display: contents host; style its message part). —
spinner The busy ring in the field while loading . —
clear The clear button ( clearable ). —
panel The overlay panel, rendered in the overlay container. —
listbox The role="listbox" list inside the panel. —
option One option ( aria-selected , aria-disabled ). —
empty The "no results" row. —
loading The loading row at the top of the panel. —
check The check mark of the selected option. —

Accessibility

  • Follows the APG combobox-with-list-autocomplete pattern: the input has role="combobox", aria-autocomplete="list", aria-expanded and aria-controls pointing at a role="listbox".
  • Focus stays in the input. ArrowDown and ArrowUp move through the suggestions (exposed with aria-activedescendant), Enter picks one, Escape closes the list.
  • While loading the input sets aria-busy and the list shows a role="status" message (loadingLabel), so the wait is announced.
  • The input is named by a real <label for>; hint and error are linked through aria-describedby. clearAriaLabel, emptyMessage and loadingLabel translate the added texts.

API

Autocomplete

vig-autocomplete component

Text field with a suggestion list (APG combobox with list autocomplete). Suggestions come from options, filtered locally by label, or from the server: listen to searchRequest (debounced), set localFilter to false, and feed the results back through options while loading shows a spinner. Focus stays in the input; the active option is exposed through aria-activedescendant. Empty is null.

Autocomplete props
Name Type Default Description
allowCustombooleanfalse

Keeps typed text that matches no option as the value (string models).

clearablebooleanfalse
—
clearAriaLabelstring | undefinedundefined
—
debouncenumber250

Delay before searchRequest fires, in milliseconds.

dirtybooleanfalse
—
disabledbooleanfalse
—
disabledReasonsreadonly WithOptionalFieldTree<DisabledReason>[][]
—
displayWith((value: T) => string) | undefinedundefined

Text shown in the field for a value; defaults to the option label.

emptyMessagestring | undefinedundefined
—
errorMessagesRecord<string, string>—
—
errorsreadonly ValidationError.WithOptionalFieldTree[][]
—
hiddenbooleanfalse
—
hideLabelbooleanfalse

Visually hides the label; it still names the control for assistive tech.

hintstring | undefinedundefined
—
invalidbooleanfalse
—
label required string—
—
labelPositionLabelPosition'float'

float (default) rests the label inside the field; top sets it above a shorter field, for forms laid out with labels over their controls.

loadingbooleanfalse

Shows a spinner while server suggestions are on their way.

loadingLabelstring | undefinedundefined
—
localFilterbooleantrue

Narrows options by the typed text. Turn off when searchRequest feeds server results.

minQueryLengthnumber1

Characters needed before suggestions open (0 opens on focus). Not named minLength: that input belongs to the Signal Forms text-length contract.

namestring''
—
optionsreadonly SelectOption<T>[][]
—
pendingbooleanfalse
—
placeholderstring | undefinedundefined
—
readonlybooleanfalse
—
requiredbooleanfalse
—
sizeFieldSize'md'
—
touchedbooleanfalse
—
value model T | nullnull
—

SelectOptionTemplate

ng-template[vigSelectOption] directive

Custom rendering for options of vig-select, vig-multi-select, vig-listbox and vig-select-button, replacing the default icon + label. vig-select also uses it for the selected value shown in the trigger.

Bind the same options to vigSelectOptionOf (like ngForOf) to type let-option in the template; without it the option value is unknown.

Example :
<vig-select label="Status" [options]="statuses">
  <ng-template vigSelectOption [vigSelectOptionOf]="statuses" let-option>
    <i [class]="option.value" aria-hidden="true"></i> {{ option.label }}
  </ng-template>
</vig-select>
SelectOptionTemplate props
Name Type Default Description
vigSelectOptionOfreadonly SelectOption<T>[] | null | undefinedundefined

Type-only: the options the template renders, so the template type checker infers the option value type. Not read at runtime.

VigValueAccessor

directive

Bridges the vigdx form fields to Reactive Forms (formControl, formControlName) and template-driven forms (ngModel). Import it next to the component; Signal Forms ([formField]) need no accessor.

VigValueAccessor methods
Signature Description
registerOnChange(fn: (value: unknown) => void): void
—
registerOnTouched(fn: () => void): void
—
setDisabledState(disabled: boolean): void
—
writeValue(value: unknown): void
—

Are you sure?