Autocomplete

Free text with suggestions: the value is what is typed, and a suggestion picked completes it. When the value must be one of the options, use the Combobox.

FormsExperimental

Usage

Usage

Value: “”

import { Component, ViewEncapsulation, signal } from '@angular/core';import {  ScAutocomplete,  ScComboboxEmpty,  ScComboboxInput,  ScComboboxItem,  ScComboboxList,  ScComboboxPopup,  ScComboboxPortal,  ScField,

Anatomy

A root holding the text, and inside it the Combobox's parts as they are: the input, the popup, the list and its items, groups, an empty text, a status. You filter the suggestions by query().

import {  ScAutocomplete, ScComboboxInput, ScComboboxPortal, ScComboboxPopup,  ScComboboxList, ScComboboxItem, ScComboboxEmpty, scComboboxMatches,} from '@semantic-components/ui';
<div scAutocomplete [formField]="…" #ac="scAutocomplete">  <input scInput scComboboxInput />  <ng-template scComboboxPortal>    <div scComboboxPopup>      <div scComboboxEmpty>…</div>      <div scComboboxList aria-label="…">        @for (item of matching(ac.query()); track item) {          <div scComboboxItem [value]="item">{{ item }}</div>        }      </div>    </div>  </ng-template></div>

Accessibility

  • WAI-ARIA's editable combobox: focus stays in the input. ↓ and ↑ open the list and move the highlight, Enter picks, Escape closes.
  • aria-autocomplete says how it completes: list, or both with mode="both" — the highlighted suggestion typed in, selected.
  • Name the input (its field's label, or aria-label) and the list; a status (scComboboxStatus) reads out what you write, such as the number of results.

Examples

Inline completion

import { Component, ViewEncapsulation, signal } from '@angular/core';import {  ScAutocomplete,  ScComboboxEmpty,  ScComboboxInput,  ScComboboxItem,  ScComboboxList,  ScComboboxPopup,  ScComboboxPortal,  ScInput,

Groups

import { Component, ViewEncapsulation, signal } from '@angular/core';import {  ScAutocomplete,  ScComboboxEmpty,  ScComboboxGroup,  ScComboboxGroupLabel,  ScComboboxInput,  ScComboboxItem,  ScComboboxList,  ScComboboxPopup,

Async search

import {  Component,  ViewEncapsulation,  effect,  signal,  viewChild,} from '@angular/core';import {  ScAutocomplete,  ScComboboxEmpty,

Auto highlight

import { Component, ViewEncapsulation, signal } from '@angular/core';import {  ScAutocomplete,  ScComboboxEmpty,  ScComboboxInput,  ScComboboxItem,  ScComboboxList,  ScComboboxPopup,  ScComboboxPortal,  ScInput,

Limit results

import { Component, ViewEncapsulation, signal } from '@angular/core';import {  ScAutocomplete,  ScComboboxEmpty,  ScComboboxInput,  ScComboboxItem,  ScComboboxList,  ScComboboxPopup,  ScComboboxPortal,  ScComboboxStatus,

Form

Pick a country, or write your own.

{
  "destination": ""
}
import { JsonPipe } from '@angular/common';import { Component, ViewEncapsulation, signal } from '@angular/core';import { FormField, form, maxLength, required } from '@angular/forms/signals';import {  ScAutocomplete,  ScComboboxEmpty,  ScComboboxInput,  ScComboboxItem,  ScComboboxList,  ScComboboxPopup,

Icon and clear

import { Component, ViewEncapsulation, signal } from '@angular/core';import {  ScAutocomplete,  ScComboboxClear,  ScComboboxEmpty,  ScComboboxInput,  ScComboboxItem,  ScComboboxList,  ScComboboxPopup,  ScComboboxPortal,

Disabled

import { Component, ViewEncapsulation, signal } from '@angular/core';import {  ScAutocomplete,  ScComboboxEmpty,  ScComboboxInput,  ScComboboxItem,  ScComboboxList,  ScComboboxPopup,  ScComboboxPortal,  ScInput,

RTL

import { Dir } from '@angular/cdk/bidi';import { Component, LOCALE_ID, ViewEncapsulation, signal } from '@angular/core';import {  ScAutocomplete,  ScComboboxEmpty,  ScComboboxInput,  ScComboboxItem,  ScComboboxList,  ScComboboxPopup,  ScComboboxPortal,

API reference

The parts inside are the Combobox's: see its API reference. Each part takes class, merged over the style (cn: a later class wins).

PartSelectorDescription
ScAutocompletediv[scAutocomplete] The root: value, the input's text (two-way, or a [formField] of text — required, maxLength… in its schema); mode ('list', 'both': the highlighted suggestion completes the text inline); autoHighlight; openOnInputClick (off); disabled; readonly. exportAs scAutocomplete: query(), the text to filter by while open; open().
The Combobox’s parts[scCombobox…] Inside, as in a Combobox: scComboboxInput, Trigger, Clear, Portal, Popup, List, Item, Group, GroupLabel, Separator, Empty, Status. A picked item writes its label into the text.