Cascade select

A form field picking one value from nested options, such as country, region and city. Each open option shows its children beside it; on a phone the panel steps through one level at a time.

  • vig-cascade-select
Import
import { CascadeSelect, CascadeSelectOptionTemplate } from '@vigdx/ui/cascade-select';

Basic

Options are your own objects. optionLabel and optionValue are functions (by default the option's label and the option itself); optionChildren and optionDisabled read children and disabled unless you pass your own. Only options without children are chosen, which writes optionValue(option) to [(value)] ; opening the panel shows the path to the value. Hover or click opens a level, and a diagonal move toward it keeps it open.

City

Value: MUC

Choosing groups, path and option content

selectableGroups lets a region or a country be chosen too: a click on its label or Enter chooses it, its chevron or ArrowRight opens it. display="path" shows the whole path in the trigger, and a vigCascadeSelectOption template (typed by vigCascadeSelectOptionOf ) renders the options.

Delivery area

Value: TR-AE

Lazy levels

Options whose optionChildren returns undefined load through loadChildren(option, signal) the first time they open, and stay loaded. The signal aborts when the level closes first; a rejected promise shows a retry row, and an empty array makes the option a leaf (chosen at once when Enter or a click started the load). valueLabel(value) labels a value whose option is not loaded yet. Return null from optionChildren (or a children: null field) for options that never have children.

Category

Value: none

Signal Forms

Bind a field with [formField] : errors, required, disabled and touched state come from the form. Clearing writes null , so type the field as nullable.

Office

Where you work most days.

Reactive Forms

Import VigValueAccessor next to the field for formControlName , formControl and ngModel .

Warehouse

{
  "warehouse": null
}

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="cascade-select"][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="cascade-select"]

CascadeSelect styling hooks
Part Element data-state
field Positioned wrapper of the label, trigger and buttons. —
label The visible (or floating) label. —
trigger The role="combobox" button. open, closed
value The chosen option (or its path) and, for assistive tech, its ancestors. —
placeholder The placeholder text in the trigger. —
indicator The chevron. —
clear The clear button ( clearable ). —
panel The overlay panel of the top level, in the overlay container. —
header Narrow screens: the row above a deeper level. —
back Narrow screens: the button back to the previous level. —
heading Narrow screens: the label of the open option. —
listbox The role="listbox" of the level the panel shows, named by its option (the field at the top; aria-busy while it loads). —
level Wide screens: an open option's children, a role="listbox" named by it, in an overlay beside it. —
option A role="option" ( aria-selected , aria-disabled ; options with children are described as having options and are aria-busy while they load). open, closed
option-label The option text (without a custom template). —
check The check mark of the chosen option. —
group-indicator The chevron of an option with children. —
loading The busy ring of an option whose children load. —
level-status The loading row of a level that waits for its options. —
load-error The row of a level whose options failed to load. —
retry The retry text of that row. —
empty The row shown without options. —
status The visually hidden role="status" region announcing the level entered. —
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). —
CascadeSelect data attributes
Attribute Meaning
data-opening On the overlay element (panel or <dialog> ) while its entrance transition plays; removed once it settles (2s at most). Style the entrance with data-opening: utilities.
data-closing On the overlay element while its exit transition plays, before it closes; removed once it settles (2s at most). Style the closed look with data-closing: utilities.

Accessibility

  • The trigger is an APG role="combobox" labelled by the field label, with aria-haspopup="listbox". Each level is a role="listbox" named by its option ("Türkiye"; the top level by the field). Focus stays on the trigger: its aria-controls names the listbox of the active level and aria-activedescendant the active option there; both are left out while the element they name is not on the page (a level still attaching or loading).
  • Options with a level of their own are described as having options ("has options"), and entering a level is announced through a polite status ("Türkiye, 3 options").
  • ArrowDown, ArrowUp, Enter or Space open the panel on the value's path. ArrowUp and ArrowDown move within a level, Home and End to its ends, ArrowRight opens the active option's level and moves into it, ArrowLeft goes back (mirrored in right-to-left pages), typing jumps to an option, Enter or Space chooses it, Escape closes the panel and Tab closes it and moves on.
  • The value reads with its path, the option first: "Istanbul, Marmara, Türkiye". An option whose children load is aria-busy and described by the loading text; a failed load becomes a retry option in its level, and reopening the panel tries again. A value under a disabled option still shows, but the panel opens on the nearest enabled option.
  • On narrow screens the Back button (and ArrowLeft) returns to the previous level; its targets, like the options, are at least 44px tall on touch screens.
  • Texts are translated with the locale or per instance through labels (ariaLabel, clearAriaLabel, backLabel, hasOptionsLabel, levelAnnouncement, loadingLabel, errorLabel, retryLabel, emptyLabel).

API

CascadeSelect

vig-cascade-select component

A form field picking one value from nested options, e.g. country → state → city: the panel shows a level per open option, side by side, and choosing an option without children sets the value. On narrow screens the panel shows one level at a time with a Back button.

Options are your own objects: optionLabel, optionValue, optionChildren and optionDisabled read them (by default their label, the option itself, children and disabled), and loadChildren fetches levels on demand. Values compare with ===.

Example :
<vig-cascade-select label="City" [options]="countries" [optionValue]="cityCode" [formField]="form.city" />

The trigger is a combobox (APG) whose popup is the listbox of the active level: focus stays on it and the arrow keys move the active option (aria-activedescendant), Right (Left in RTL) opens a level, Left goes back, Enter picks, typing jumps to an option. The chosen value is announced with its path ("Istanbul, Türkiye"). Works with Signal Forms and, through VigValueAccessor, with Reactive Forms and ngModel.

While it plays its entrance or exit transition, the animating element carries data-opening or data-closing (stable hooks for styling and for waiting in tests; see the theming guide). panel listbox level option option-label check group-indicator loading level-status load-error retry empty header back heading status cascade-select open closed data-opening data-closing

CascadeSelect props
Name Type Default Description
clearablebooleanfalse

Shows a button that clears the value while one is set.

dirtybooleanfalse
—
disabledbooleanfalse
—
disabledReasonsreadonly WithOptionalFieldTree<DisabledReason>[][]
—
display"label" | "path"'label'

The trigger shows the chosen option's label, or its whole path ("Türkiye / Istanbul").

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

Visually hides the label, which still names the field; pair it with a placeholder.

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

float (default) rests the label inside the field; top sets it above.

labelsPartial<CascadeSelectLabels>—

Texts (i18n); locale defaults.

loadChildrenCascadeSelectLoader<T> | undefinedundefined

Fetches the children of options without their own; see CascadeSelectLoader.

namestring''
—
optionChildrenCascadeSelectChildren<T>defaultOptionChildren

Children of an option: an array (empty or null for a leaf), or undefined for children loadChildren fetches. Its children by default.

optionDisabled(option: T) => booleandefaultOptionDisabled

Whether an option is disabled: dimmed, skipped by the keys, never opened or chosen.

optionLabel(option: T) => stringdefaultOptionLabel

Text of an option; its label (else the option as text) by default.

optionsreadonly T[][]

The top-level options.

optionValue(option: T) => Videntity

What choosing an option writes to value; the option itself by default. Compared with ===.

pendingbooleanfalse
—
placeholderstring | undefinedundefined

Shown in the trigger while nothing is chosen.

readonlybooleanfalse
—
requiredbooleanfalse
—
selectableGroupsbooleanfalse

Options with children can be chosen too (Enter or a click on the label); the chevron opens them.

sizeFieldSize'md'
—
touchedbooleanfalse
—
value model V | nullnull

The value of the chosen option (optionValue); null while none is.

valueLabel((value: V) => string | undefined) | undefinedundefined

Labels a value whose option is not known: not loaded yet (under a lazy option) or gone from options. Without it, or when it returns undefined, the trigger shows the value as text (an object value with the default optionValue shows its optionLabel).

CascadeSelectOptionTemplate

ng-template[vigCascadeSelectOption] directive

Custom content of the options of vig-cascade-select (in the panel; the trigger keeps the label text, and options keep optionLabel as their accessible name). Bind the same top-level options to vigCascadeSelectOptionOf to type let-option; without it the option is unknown.

Example :
<ng-template vigCascadeSelectOption [vigCascadeSelectOptionOf]="places" let-place>
  <span aria-hidden="true">{{ place.flag }}</span> {{ place.name }}
</ng-template>
CascadeSelectOptionTemplate props
Name Type Default Description
vigCascadeSelectOptionOfreadonly T[] | null | undefinedundefined

Type-only: the options the template renders. Not read at runtime.

Are you sure?