Listbox

A list of options shown in the page rather than in a dropdown: one or many values, with an optional filter, checkboxes, groups and virtual scrolling for long lists. The value is always an array.

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

Basic

Pass options as ListboxOption objects ( SelectOption plus an optional group ) and bind [(value)] to an array; empty is [] . Without multiple it holds at most one value, which follows the arrow keys like a native <select size> ; the value stays an array either way, so a single-choice form field is typed T[] .

City
İstanbul
Berlin
Lisbon
Oslo
Paris
Rome
Vienna

Value: [ "lis" ]

Multiple, checkboxes, filter and groups

multiple keeps the values in selection order. checkbox adds a checkbox per option and a select-all row (only with multiple ; a dev-mode warning says so otherwise), filter a search field that matches labels in the active locale. Consecutive options with the same group form a named group.

Cities
İstanbul
Berlin
Lisbon
Oslo
Paris
Rome
Vienna

Toppings
Herbs
Basil
Oregano
Vegetables
Olives
Peppers
Mushrooms
Cheese
Mozzarella
Gorgonzola

Cities: [] · Toppings: [ "basil" ]

Long lists

From 500 options on ( virtualScroll is 'auto' ) only the rows in view are rendered, with one row height; set virtualScroll to true or false to decide yourself. The height follows --vig-listbox-max-height (15rem), the virtual row height --vig-listbox-row-height (2.25em).

Invoices

0 of 10 000 selected

Custom options and texts

A vigSelectOption template renders each option, as in vig-select ; labels overrides the texts the list adds ( filterPlaceholder , filterAriaLabel , emptyLabel , noResultsLabel , selectAllLabel ).

Folder
Inbox12
Drafts3
Archive248

Forms

vig-listbox implements FormValueControl<T[]> for Signal Forms; import VigValueAccessor for formControl , formControlName or ngModel . Signal Forms' required() treats [] as filled, so require a value with minLength(path, 1) or check the length with validate() . Values compare with === and must be unique (a dev-mode warning flags duplicates).

Signal Forms
İstanbul
Berlin
Lisbon
Oslo
Paris
Rome
Vienna

Pick two or more.

Reactive Forms
İstanbul
Berlin
Lisbon
Oslo
Paris
Rome
Vienna

Valid: no · Home: []

Listbox or select

A listbox keeps every option on screen, which suits a handful of choices that people compare or a long list they scan with a filter. When space is short, use a select or a multi select: the same options and value in a dropdown. To order a list, or to move items between two lists, use an order list or a pick list, which build on the listbox.

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="listbox"][data-part="label"] { … }: 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="listbox"]

Listbox styling hooks
Part Element data-state
label The visible (or visually hidden) label naming the list. —
control The bordered box around the filter, select-all row, list and status. —
filter The search field above the list ( filter ). —
select-all The select-all toggle ( checkbox with multiple ; aria-pressed ). —
listbox The focusable role="listbox" ; a cdk-virtual-scroll-viewport while virtualized. —
group A role="group" of options sharing a group heading. —
group-heading The heading of a group (a hidden-from-AT row while virtualized). —
option One option ( aria-selected , aria-disabled ). selected
checkbox The checkbox of an option ( checkbox ). —
check The check mark of a selected option (without checkbox ). —
status The polite role="status" region under the list. —
empty The "no options" or "no results" message in the status. —
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). —

Accessibility

  • Follows the WAI-ARIA APG listbox pattern: a role="listbox" named by the label, with aria-multiselectable in multiple mode, and options reporting aria-selected and aria-disabled.
  • Focus stays on the list and points at the active option through aria-activedescendant, so it keeps working while the list is virtualized; the active option draws an outline that forced-colors mode keeps, and selection shows a check mark or checkbox, never a tint alone. While virtualized, options carry aria-setsize and aria-posinset, the reference is set only while the active option is rendered, and the group name describes each option.
  • ArrowUp and ArrowDown move, Home and End jump, PageUp and PageDown move a page, typing jumps to a matching label. In single mode the selection follows; in multiple mode Space toggles, Shift+arrows toggle the next option, Shift+Space and Shift+click select a range, Ctrl+Shift+Home/End select to the ends and Ctrl/Cmd+A selects every option (again to clear).
  • The filter is a search field controlling the list; ArrowDown moves on into the list. When nothing matches, a status message says so.
  • Hint and error are linked through aria-describedby; an invalid list sets aria-invalid, a read-only one aria-readonly (it can still be browsed), a disabled one (aria-disabled) stays focusable, so a long list can still be scrolled and read, but nothing can be selected.

API

Listbox

vig-listbox component

A list of options shown in the page (APG listbox): one or many values, an optional filter, checkboxes, groups and virtual scrolling for long lists. Focus stays on the list and the active option is exposed through aria-activedescendant, so it keeps working while virtualized. The value is always an array in selection order ([] when empty); single selection holds at most one value and follows the arrow keys, like a native <select size>.

Example :
<vig-listbox label="Cities" [options]="cities" [(value)]="picked" multiple filter />
Listbox props
Name Type Default Description
checkboxbooleanfalse

With multiple, a checkbox per option and a select-all row; ignored (with a dev-mode warning) without it.

dirtybooleanfalse
—
disabledbooleanfalse
—
disabledReasonsreadonly WithOptionalFieldTree<DisabledReason>[][]
—
errorMessagesRecord<string, string>—
—
errorsreadonly ValidationError.WithOptionalFieldTree[][]
—
filterbooleanfalse

A search field above the list that narrows the options by label (locale-aware).

hiddenbooleanfalse
—
hideLabelbooleanfalse

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

hintstring | undefinedundefined
—
invalidbooleanfalse
—
label required string—

Visible label naming the list; also with hideLabel.

labelsPartial<ListboxLabels>—

Texts (i18n) over the locale defaults.

multiplebooleanfalse

Allows any number of values: Space toggles, Shift extends, Ctrl/Cmd+A selects all. Without it the value still is an array, of at most one value; a Signal Forms required() does not see [] as empty, so check it with minLength(path, 1).

namestring''
—
optionsreadonly ListboxOption<T>[][]

The options; values compare with ===, so each must be unique.

pendingbooleanfalse
—
readonlybooleanfalse
—
requiredbooleanfalse
—
sizeFieldSize'md'

Text size and option padding.

touchedbooleanfalse
—
value model T[][]

The selected values in selection order; at most one without multiple.

virtualScrollListboxVirtualScroll'auto'

Renders only the options in view; 'auto' from LISTBOX_VIRTUAL_THRESHOLD options (and back below 400). A virtualized list cannot be dragged.

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?