Tree select

A form field whose panel holds a tree: pick a category, a region or a folder from a hierarchy. Its value is an array of node keys in every mode, so changing between one and several values never changes its type.

  • vig-tree-select
Import
import { TreeSelect } from '@vigdx/ui/tree-select';

Basic

Pass the same TreeNode objects as vig-tree takes. In single mode (the default) a click or Enter picks a node and closes the panel; [(value)] holds [key] , or [] when cleared. Opening the panel reveals the selected node.

Ships to

Value: [ "de" ]

Several values

multiple toggles nodes and checkbox checks whole branches (tri-state, with cascade ); the panel stays open. The trigger shows the labels comma-separated or as removable chips ( display="chip" ), a fully checked branch as its top node, and selectedItemsLabel above maxSelectedLabels . filter adds a search field; typing on the closed field starts the search, and virtual keeps large trees fast. Disabled values keep their state: their chips have no remove button and clearing leaves them. A key whose node is not loaded (yet) shows keyLabel(key) , else the key itself; such keys stay when an ancestor is unchecked, since the field cannot tell they lie below it.

Markets

Offices

Signal Forms

Bind a field with [formField] : errors, required, disabled and touched state come from the form. An array field expresses “at least one” with minLength .

Regions

Pick at least one.

Reactive Forms

Import VigValueAccessor next to the field for formControlName , formControl and ngModel . A reset writes [] .

Warehouse region

{
  "region": []
}

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

TreeSelect 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" element. open, closed
value The selected label, comma list or "{0} selected" summary. —
chip A vig-chip per shown value ( display="chip" ). —
placeholder The placeholder text in the trigger. —
indicator The chevron. —
clear The clear button ( clearable ). —
panel The role="dialog" panel, in the overlay container; the tree in it keeps the Tree parts. —
filter The search field at the top of the panel ( filter ). —
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). —
TreeSelect 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 a role="combobox" labelled by the field label, with aria-haspopup="dialog" and aria-expanded; its panel is a role="dialog" named like the field, holding the search field and a vig-tree with all of its keyboard support.
  • ArrowDown, ArrowUp, Enter or Space open the panel and move focus to the selected node (or the first one), or to the search field with filter; ArrowDown in the search field moves on to the tree. Escape closes the panel and returns focus to the trigger; Tab closes it and moves on from the trigger.
  • Texts are translated with the locale or per instance through labels (clearAriaLabel, removeAriaLabel, filterAriaLabel, selectedItemsLabel and the tree's loading, error and empty texts).

API

TreeSelect

vig-tree-select component

A form field whose panel holds a vig-tree: pick one node (single), several (multiple), or check whole branches (checkbox). The value is always an array of node keys, so switching mode never changes its type and it survives reloading the data. Several values show as text or chips (display), and filter adds a search field above the tree.

Example :
<vig-tree-select label="Category" [nodes]="categories" [formField]="form.category" />

The trigger is a combobox opening a dialog (aria-haspopup="dialog"): focus moves into the tree (or its search field), Escape closes it and returns to the trigger. 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). data-opening data-closing

TreeSelect props
Name Type Default Description
cascadebooleantrue

checkbox mode: checking a node checks its branch; parents follow their children.

clearablebooleanfalse

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

dirtybooleanfalse
—
disabledbooleanfalse
—
disabledReasonsreadonly WithOptionalFieldTree<DisabledReason>[][]
—
display"comma" | "chip"'comma'

Several values: comma-separated text, or removable chips.

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

Adds a search field above the tree; matches show with their ancestors.

hiddenbooleanfalse
—
hideLabelbooleanfalse

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

hintstring | undefinedundefined
—
invalidbooleanfalse
—
keyLabel((key: string) => string | undefined) | undefinedundefined

Labels a selected key whose node is not known: not loaded yet (under a lazy node) or gone from nodes. Without it, or when it returns undefined, the trigger shows the key itself. Such keys stay in the value when an ancestor is unchecked, since the field cannot tell that they lie below it.

label required string—
—
labelPositionLabelPosition'float'

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

labelsPartial<TreeSelectLabels>—

Texts (i18n); locale defaults.

loadChildrenTreeLoader<T> | undefinedundefined

Fetches the children of nodes that have none of their own; see TreeLoader.

maxSelectedLabelsnumber3

Above this many values the trigger shows selectedItemsLabel instead.

namestring''
—
nodesreadonly TreeNode<T>[][]

The top-level nodes.

pendingbooleanfalse
—
placeholderstring | undefinedundefined

Shown in the trigger while nothing is selected.

readonlybooleanfalse
—
requiredbooleanfalse
—
selectionModeTreeSelectMode'single'

single (closes on pick), multiple or checkbox.

sizeFieldSize'md'
—
touchedbooleanfalse
—
value model readonly string[][]

Keys of the selected nodes; empty when nothing is selected.

virtualbooleanfalse

Renders only the rows in view in the panel's tree, for large trees (see vig-tree).

Are you sure?