Listbox
One option or several, chosen from a list always in view — like a native select with several rows. In a form, the value chosen, or the values.
Usage
Usage
basil
import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScField, ScLabel, ScListbox, ScListboxItem, ScListboxItemIndicator,} from '@semantic-components/ui';import { SiCheckIcon } from '@semantic-icons/lucide-icons';Anatomy
The list holds options only — and groups, separators. Buttons, a search, an empty message go beside it.
import { ScListbox, ScListboxGroup, ScListboxGroupLabel, ScListboxItem, ScListboxItemIcon, ScListboxItemIndicator, ScListboxMultiple, ScListboxSeparator } from '@semantic-components/ui';<div scListbox [formField]="form.topping"> <div scListboxGroup> <div scListboxGroupLabel>Cheeses</div> <div scListboxItem value="brie"> <span scListboxItemIcon><svg …></svg></span> Brie <span scListboxItemIndicator><svg siCheckIcon></svg></span> </div> </div> <div scListboxSeparator></div></div>Choosing
scListbox holds one value (or null); scListbox multiple an array, in the list's order. With activationautomatic — one value's default — the option under focus is chosen; with manual — several's default — Space, Enter or a click chooses. deselectable lets the chosen option be pressed off. In a form, an empty array is not empty to Signal Forms' required(): use minLength(path, 1).
Keyboard
| Key | Does |
|---|---|
| ↑↓ (←→ horizontal) | The previous / next option (wrapping, unless loop is off) |
| Home / End | The first / last option |
| Letters | The next option starting with them |
| Space / Enter | Chooses (toggles, with several) |
| Shift + ↑Shift + ↓ | With several: a range |
| Ctrl + Shift + Home / Ctrl + Shift + End | With several: the range to the first / last |
| Ctrl + A | With several: all (again: none) |
| Ctrl + ↑Ctrl + ↓, Ctrl + Space | With several, automatic: move without choosing; toggle |
Accessibility
- A listbox (multiselectable with several), its options saying whether they are chosen; named by its field's label or
aria-label. - One Tab stop: the chosen option (or the first). With
virtualFocus, focus stays on the list, which points at the option under it. - Groups are named by their label; separators and icons are hidden from screen readers; the check is decorative.
Examples
Multiple
cheese, onion
import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScField, ScLabel, ScListboxItem, ScListboxItemIndicator, ScListboxMultiple,} from '@semantic-components/ui';import { SiCheckIcon } from '@semantic-icons/lucide-icons';Selection that follows focus
1 selected
import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScListboxItem, ScListboxItemIcon, ScListboxItemIndicator, ScListboxMultiple,} from '@semantic-components/ui';import { SiCheckIcon, SiFileIcon } from '@semantic-icons/lucide-icons';
/** activation="automatic" with several: the arrows choose — Ctrl + arrow moves without choosing, Ctrl + Space or Ctrl-click adds. */Manual activation
None
import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScListbox, ScListboxItem, ScListboxItemIndicator,} from '@semantic-components/ui';import { SiCheckIcon } from '@semantic-icons/lucide-icons';
/** activation="manual": the arrows only move — Space, Enter or a click chooses. Nothing chosen at first. */@Component({Focus on the list
None
import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScListbox, ScListboxItem, ScListboxItemIndicator,} from '@semantic-components/ui';import { SiCheckIcon } from '@semantic-icons/lucide-icons';
/** virtualFocus: focus stays on the list, the option under it pointed at (aria-activedescendant) — as a combobox does. */@Component({Deselectable
astro
import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScListbox, ScListboxItem, ScListboxItemIndicator,} from '@semantic-components/ui';import { SiCheckIcon } from '@semantic-icons/lucide-icons';
/** deselectable: the chosen option, pressed again, is no longer chosen. */@Component({Groups
banana
import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScListboxGroup, ScListboxGroupLabel, ScListboxItem, ScListboxItemIndicator, ScListboxMultiple, ScListboxSeparator,} from '@semantic-components/ui';import { SiCheckIcon } from '@semantic-icons/lucide-icons';Icons
import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScListbox, ScListboxItem, ScListboxItemIcon, ScListboxItemIndicator,} from '@semantic-components/ui';import { SiCheckIcon, SiFileTextIcon,Horizontal
M
import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScListbox, ScListboxItem } from '@semantic-components/ui';
/** orientation="horizontal": ← → move (as the text reads); loop off — they stop at the ends; XL disabled, skipped. */@Component({ selector: 'app-horizontal-listbox-demo', imports: [ScListbox, ScListboxItem], template: ` <div class="grid gap-2"> <divDisabled
import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScButton, ScListboxItem, ScListboxItemIndicator, ScListboxMultiple,} from '@semantic-components/ui';import { SiCheckIcon } from '@semantic-icons/lucide-icons';
/** An option disabled (skipped by the arrows, typing and ranges), or the whole list — out of the Tab order. */Read-only
import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScListbox, ScListboxItem, ScListboxItemIndicator,} from '@semantic-components/ui';import { SiCheckIcon } from '@semantic-icons/lucide-icons';
/** readonly: focusable and browsable, its value kept — not changed. */@Component({Form
import { Component, ViewEncapsulation, signal } from '@angular/core';import { FormField, FormRoot, form, maxLength, minLength,} from '@angular/forms/signals';import { ScButton,Object values
pro
import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScListbox, ScListboxItem, ScListboxItemIndicator,} from '@semantic-components/ui';import { SiCheckIcon } from '@semantic-icons/lucide-icons';
/** Values are any type: here the plans themselves — the same objects in the options and in the value. */@Component({Methods
None
import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScButton, ScListboxItem, ScListboxItemIndicator, ScListboxMultiple,} from '@semantic-components/ui';import { SiCheckIcon } from '@semantic-icons/lucide-icons';
/** #list="scListbox": selectAll(), clear(), focus(). */Scrollable
import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScListbox, ScListboxItem, ScListboxItemIndicator,} from '@semantic-components/ui';import { SiCheckIcon } from '@semantic-icons/lucide-icons';
/** A long list in a set height: the option under focus — and the chosen one, at first — scrolled into view. */@Component({RTL
import { Dir } from '@angular/cdk/bidi';import { Component, LOCALE_ID, ViewEncapsulation, signal } from '@angular/core';import { ScField, ScLabel, ScListbox, ScListboxItem, ScListboxItemIndicator,} from '@semantic-components/ui';import { SiCheckIcon } from '@semantic-icons/lucide-icons';API reference
Each part takes class, merged over its own (cn: a later class wins). The box is the style's (listbox, as its textarea); options, indicator, group labels and separators are its combobox's.
| Part | Selector | Description |
|---|---|---|
ScListbox | div[scListbox] | The list, one value (T | null). exportAs scListbox: clear(), focus(). |
ScListboxMultiple | div[scListbox][multiple] | The list, several values (T[]). exportAs scListbox: selectAll(), clear(), focus(). |
ScListboxItem | [scListboxItem] | An option: [value], label, disabled. data-selected, data-active. |
ScListboxItemIndicator | [scListboxItemIndicator] | Its content shown while the option is chosen. |
ScListboxItemIcon | [scListboxItemIcon] | An icon at the start: hidden from screen readers; mirror. |
ScListboxGroup | div[scListboxGroup] | Options together, named by their label. |
ScListboxGroupLabel | [scListboxGroupLabel] | A group's name. |
ScListboxSeparator | [scListboxSeparator] | A line between groups; hidden from screen readers. |
| Input | Type | Default | Description |
|---|---|---|---|
value | T | null (several: T[]) | null ([]) | Two-way, or [formField]. |
activation | 'automatic' | 'manual' | automatic (several: manual) | Whether the option under focus is chosen. |
deselectable | boolean | false | One value: the chosen option, pressed again, is not. |
orientation | 'vertical' | 'horizontal' | 'vertical' | Which arrows move. |
loop | boolean | true | The arrows wrap. |
virtualFocus | boolean | false | Focus stays on the list (aria-activedescendant). |
disabled, readonly, required, invalid, touched | boolean | false | Bound by [formField]. |
| Input | Type | Default | Description |
|---|---|---|---|
value | T | — | Required: what choosing it gives. |
label | string | its text | What typing finds it by. |
disabled | boolean | false | Not chosen; skipped by the arrows, typing and ranges. |