Select

A choice among a short list of options: a trigger showing the value, the options in a popup below it. In the look of the app's style, with Signal Forms. For a long list to filter, use a Combobox; for several values, a Multiselect.

FormsExperimental

Usage

import { Component, ViewEncapsulation, signal } from '@angular/core';import {  ScField,  ScLabel,  ScSelect,  ScSelectGroup,  ScSelectIcon,  ScSelectItem,  ScSelectItemIndicator,  ScSelectItemText,  ScSelectList,  ScSelectPopup,  ScSelectPortal,  ScSelectTrigger,  ScSelectValue,} from '@semantic-components/ui';import { SiCheckIcon, SiChevronDownIcon } from '@semantic-icons/lucide-icons';
@Component({  selector: 'app-select-usage-demo',  imports: [    ScField,    ScLabel,    ScSelect,    ScSelectGroup,    ScSelectIcon,    ScSelectItem,    ScSelectItemIndicator,    ScSelectItemText,    ScSelectList,    ScSelectPopup,    ScSelectPortal,    ScSelectTrigger,    ScSelectValue,    SiCheckIcon,    SiChevronDownIcon,  ],  template: `    <div scField class="w-full max-w-48">      <label scLabel>Theme</label>      <div scSelect [(value)]="theme" [items]="themes">        <button scSelectTrigger>          <span scSelectValue placeholder="Select a theme"></span>          <svg scSelectIcon siChevronDownIcon></svg>        </button>        <ng-template scSelectPortal>          <div scSelectPopup>            <div scSelectList>              <div scSelectGroup>                @for (item of themes; track item.value) {                  <div scSelectItem [value]="item.value">                    <span scSelectItemText>{{ item.label }}</span>                    <span scSelectItemIndicator>                      <svg siCheckIcon></svg>                    </span>                  </div>                }              </div>            </div>          </div>        </ng-template>      </div>    </div>  `,  host: { class: 'flex w-full justify-center' },  encapsulation: ViewEncapsulation.None,})export class SelectUsageDemo {  private readonly themes = [    { value: 'light', label: 'Light' },    { value: 'dark', label: 'Dark' },    { value: 'system', label: 'System' },  ];  private readonly theme = signal('');}

Anatomy

The select round its trigger; the popup in a template, rendered while it is open. Every part is a directive on your element; the icons are yours. It needs a name: its field's label (scLabel, before it in a scField: a click on it focuses the trigger without opening the list), or aria-label on the trigger.

import {  ScSelect, ScSelectTrigger,  ScSelectValue, ScSelectIcon, ScSelectPortal,  ScSelectPopup, ScSelectScrollUpButton, ScSelectList,  ScSelectGroup, ScSelectGroupLabel, ScSelectItem,  ScSelectItemText, ScSelectItemIndicator,  ScSelectSeparator, ScSelectScrollDownButton,} from '@semantic-components/ui';
<div scSelect [formField]="form.fruit" [items]="fruits">  <button scSelectTrigger>    <span scSelectValue placeholder="…"></span>    <svg scSelectIcon></svg>  </button>  <ng-template scSelectPortal>    <div scSelectPopup>      <div scSelectScrollUpButton><svg></svg></div>      <div scSelectList>        <div scSelectGroup>          <div scSelectGroupLabel>Group</div>          <div scSelectItem value="…">            <span scSelectItemText>Item</span>            <span scSelectItemIndicator><svg></svg></span>          </div>        </div>        <div scSelectSeparator></div>      </div>      <div scSelectScrollDownButton><svg></svg></div>    </div>  </ng-template></div>

Keyboard

Focus stays on the trigger. Enter, Space or the arrow keys open the list; the arrows, Home and End move through it; Enter or Space selects; Escape closes; typing a letter goes to the first option that starts with it, open or closed.

Examples

Groups

import { Component, ViewEncapsulation, signal } from '@angular/core';import {  ScField,  ScLabel,  ScSelect,  ScSelectGroup,  ScSelectGroupLabel,  ScSelectIcon,  ScSelectItem,  ScSelectItemIndicator,

Scrollable

import { Component, ViewEncapsulation, signal } from '@angular/core';import {  ScField,  ScLabel,  ScSelect,  ScSelectGroup,  ScSelectGroupLabel,  ScSelectIcon,  ScSelectItem,  ScSelectItemIndicator,

Disabled

import { Component, ViewEncapsulation } from '@angular/core';import {  ScField,  ScLabel,  ScSelect,  ScSelectGroup,  ScSelectIcon,  ScSelectItem,  ScSelectItemIndicator,  ScSelectItemText,

Invalid

import { Component, ViewEncapsulation, signal } from '@angular/core';import { FormField, form, required } from '@angular/forms/signals';import {  ScField,  ScFieldErrors,  ScLabel,  ScSelect,  ScSelectGroup,  ScSelectIcon,  ScSelectItem,

RTL

import { Dir } from '@angular/cdk/bidi';import { Component, LOCALE_ID, ViewEncapsulation, signal } from '@angular/core';import {  ScField,  ScLabel,  ScSelect,  ScSelectGroup,  ScSelectGroupLabel,  ScSelectIcon,  ScSelectItem,

API reference

ScSelect — div[scSelect]

The select: its value, bound with [formField] or [(value)]. It sets the width (its content’s by default, or a class): the trigger fills it, the list matches the trigger. In a field, named by the field’s label.

InputTypeDefaultDescription
valueT (string by default)'' The selected option’s value — a string, a number, an object, as its options’; '' or null: none.
items{ value: T; label: string }[][] The options’ labels, to show the value before the list has first opened.
disabledbooleanfalse Not opened. With [formField], from the schema.
classstring'' Classes merged over the style (cn: a later class wins).

ScSelectTrigger — button[scSelectTrigger]

The combobox showing the value: a native button, which the field’s label ties to by for (a click on the label focuses it, without opening the list). In a field, the field’s id; described by its description and errors.

InputTypeDefaultDescription
size'default' | 'sm''default' Its height: 32 or 28 px.
classstring'' Classes merged over the style (cn: a later class wins).

ScSelectValue — span[scSelectValue]

The selected option’s label, or the placeholder. Its content, if any, shows the value your way.

InputTypeDefaultDescription
placeholderstring'' Shown while nothing is selected.
classstring'' Classes merged over the style (cn: a later class wins).

ScSelectPopup — div[scSelectPopup]

The popup round the list, in the portal template; it scrolls between its scroll buttons.

InputTypeDefaultDescription
classstring'' Classes merged over the style (cn: a later class wins).

ScSelectItem — div[scSelectItem]

An option. Its label is label, or its text (for the value and type-ahead).

InputTypeDefaultDescription
valueT— Its value: the select’s when chosen.
labelstringits text Its label.
disabledbooleanfalse Shown dimmed, skipped by the keyboard, not chosen.
classstring'' Classes merged over the style (cn: a later class wins).

ScSelectGroup, ScSelectGroupLabel — div[scSelectGroup], div[scSelectGroupLabel]

Options together: a group, named by its label.

InputTypeDefaultDescription
classstring'' Classes merged over the style (cn: a later class wins).

ScSelectScrollUpButton, ScSelectScrollDownButton — div[scSelectScrollUpButton], div[scSelectScrollDownButton]

Shown while there is more above or below; hovering scrolls. Hidden from screen readers.

InputTypeDefaultDescription
classstring'' Classes merged over the style (cn: a later class wins).

ScSelectIcon, ScSelectItemText, ScSelectItemIndicator, ScSelectSeparator, ScSelectList, ScSelectPortal — svg[scSelectIcon], span[scSelectItemText], span[scSelectItemIndicator], div[scSelectSeparator], div[scSelectList], ng-template[scSelectPortal]

The chevron; an option’s label; the check, shown on the selected option; a line; the listbox; the popup’s template.

InputTypeDefaultDescription
classstring'' Classes merged over the style (cn: a later class wins).