Tree
vig-tree ng-template[vigTreeNode]
import { Tree, TreeNodeTemplate } from '@vigdx/ui/tree';Basic
nodes , each a TreeNode<T> with a unique key , a label , optional children , icon , disabled and typed data . selectionMode="single" makes nodes selectable (the default none is a navigation tree, where a click expands); [(value)] holds the selected keys and [(expandedKeys)] the open ones. selectable: false keeps a node out of the selection without dimming it, e.g. a folder of pickable files. nodeActivated fires on a click or Enter, for opening a file; nodeExpanded , nodeCollapsed , nodeSelected and nodeUnselected report the rest.
Selected: src/main.ts · Last opened: none
Checkboxes
selectionMode="checkbox" draws a checkbox per node. With cascade (the default) checking a folder checks its branch and a folder shows checked, unchecked or mixed from its children. Disabled and selectable: false nodes keep their own state: checking passes through them to their descendants, and their parent ignores them. While filterQuery is set, checking reaches the nodes the filter shows only. The value lists every checked key, folders included. Turn cascade off for independent checkboxes. multiple selects without checkboxes: each click toggles a node, Shift+click selects a range.
1 keys checked
Lazy loading
loadChildren(node, signal) returns a promise of the children of a node without children ; it runs on first expand, in the browser only. The node is busy meanwhile ( aria-busy ), a rejected promise shows a row that retries, and collapsing the node aborts signal , so pass it on to fetch . Mark nodes that never have children with leaf: true . Loaded children are kept per key, also across new nodes with the same keys, and dropped for keys that leave the data or when loadChildren changes; call reload(key?) when the server's data changed.
Filtering and custom nodes
filterQuery keeps the nodes whose label contains the text (case- and accent-insensitive, in the active locale), their ancestors, which open, and their descendants. Compose it with any search field. A vigTreeNode template replaces the icon and label of each node; bind [vigTreeNodeOf] to type let-node and its data .
Virtual scrolling
virtual renders only the rows in view, for trees of thousands of nodes. The tree then scrolls itself at --vig-tree-height (20rem by default) and labels stay on one line. Keyboard focus, aria-setsize and aria-posinset describe the whole tree, not the rendered window.
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"][data-part="root"] { … }: 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"]
| Part | Element | data-state |
|---|---|---|
root | vig-tree host. | — |
tree | role="tree" element (the one Tab stop is a row in it). | — |
item | role="treeitem" row ( aria-level , aria-expanded , aria-selected or aria-checked , aria-busy while its children load). | open, closed |
toggle | — | |
loading | — | |
checkbox | selectionMode="checkbox" ). | — |
icon | — | |
label | — | |
content | vigTreeNode template. | — |
error | — | |
retry | — | |
empty | role="status" region: the message without nodes or filter matches, and the announcement of a failed load. | — |
viewport | virtual tree. | — |
Accessibility
- Follows the WAI-ARIA APG treeview pattern: a
role="tree"named bylabels.ariaLabel(name every tree) ofrole="treeitem"rows witharia-level,aria-setsize,aria-posinsetandaria-expanded. Selected rows carryaria-selected, checkbox rowsaria-checked(mixedfor a partly checked folder), and the tree isaria-multiselectableinmultipleandcheckboxmodes. - The tree is one Tab stop (a roving tab index). ArrowDown and ArrowUp move, ArrowRight opens a node or enters it, ArrowLeft closes it or goes to its parent (mirrored in right-to-left pages), Home and End jump, * opens every sibling, and typing moves to the next node starting with the text. Enter and Space select (toggle in
multiple, check incheckbox); inmultiple, Shift+Arrow extends the selection and Ctrl+A selects every visible node. - A node whose children load is
aria-busyand described as loading; a failed load is announced through the tree's status region and adds a row that retries with Enter, Space or a click. - The selected row has a bar at its inline start besides its fill, and the chevron's direction shows expansion, so neither state rests on color alone; in forced-colors mode the bar takes the system Highlight color.
- With
virtual, when the focused row scrolls out of the DOM focus stays in the tree, and the arrow keys bring the row back; once the row renders again it takes focus back. Arrow, Home and End keys held with Alt, Ctrl or Meta are left to the browser.
API
Tree
vig-treeA hierarchical list (APG treeview pattern) that expands and collapses,
with optional selection: single, multiple, or tri-state checkboxes
that check whole branches. Nodes are typed (TreeNode<T>) and identified
by key, so value and expandedKeys are plain key arrays. Children can
load on first expand (loadChildren, cancelled when the node collapses),
filterQuery narrows the tree to matches and their ancestors, and
virtual renders only the rows in view, for trees of thousands of nodes.
<vig-tree [nodes]="files" selectionMode="single" [(value)]="picked"
[labels]="{ ariaLabel: 'Files' }" />One Tab stop (a roving tab index): ArrowUp/ArrowDown move, ArrowRight
expands or enters a node, ArrowLeft collapses or goes to the parent
(mirrored in RTL), Home/End jump, * expands the siblings, Enter and
Space select, and typing jumps to the next node starting with the text.
| Name | Type | Default | Description |
|---|---|---|---|
cascade | boolean | true |
|
expandedKeys | readonly string[] | [] | Keys of the expanded nodes. |
filterQuery | string | '' | Narrows the tree to the nodes whose label contains the text (case- and accent-insensitive, in the active locale), their ancestors, which expand, and their descendants. Only loaded nodes are searched. |
labels | Partial<TreeLabels> | — | Texts (i18n); locale defaults. Set |
loadChildren | TreeLoader<T> | undefined | undefined | Fetches the children of nodes that have none of their own; see
|
nodes | readonly TreeNode<T>[] | [] | The top-level nodes. |
selectionMode | TreeSelectionMode | 'none' | How nodes are selected; |
size | FieldSize | 'md' | — |
value | readonly string[] | [] | Keys of the selected (or, in |
virtual | boolean | false | Renders only the rows in view (CDK virtual scrolling), for large trees.
The tree then scrolls itself at |
| Name | Payload | Description |
|---|---|---|
expandedKeysChange | readonly string[] | Keys of the expanded nodes. |
nodeActivated | TreeNode<T> | A node was clicked or got Enter: its default action, e.g. opening a file. |
nodeCollapsed | TreeNode<T> | A node was collapsed (by the user). |
nodeExpanded | TreeNode<T> | A node was expanded (by the user). |
nodeSelected | TreeNode<T> | A node was selected, or became checked, by the user. |
nodeUnselected | TreeNode<T> | A node was unselected, or became unchecked, by the user. |
valueChange | readonly string[] | Keys of the selected (or, in |
| Signature | Description |
|---|---|
focus(): void | Moves focus to the tree's tab stop (the active, else the first selected, row). |
reload(key?: string): void | Forgets what |
TreeNodeTemplate
ng-template[vigTreeNode]Custom content of each node of vig-tree (and vig-tree-select),
replacing the default icon and label; the expand toggle and the checkbox
stay. Bind the nodes to vigTreeNodeOf to type let-node:
<vig-tree [nodes]="files">
<ng-template vigTreeNode [vigTreeNodeOf]="files" let-node>
{{ node.label }} <small>{{ node.data?.size }}</small>
</ng-template>
</vig-tree>| Name | Type | Default | Description |
|---|---|---|---|
vigTreeNodeOf | readonly TreeNode<T>[] | null | undefined | undefined | Type-only: the nodes the template renders, so |