Create

General

Tree

New
Copy page View as Markdown Open in ChatGPT Open in Claude

A hierarchy of folders and items that expand and collapse, such as a file explorer or nested navigation.

Usage#

app.component.ts
import { WdsTreeComponent } from '@wds/angular/tree';

items is a property (in HTML set it from a script): a list of { id, label, children }, where an item with children is a folder. expanded lists the open folders and value is the selected item. A click on a folder expands or collapses it (wds-toggle); a click on another item selects it (wds-change).

Examples#

Default#

Folders open and close on click and with the arrow keys. expanded sets the folders open at first.

Lines#

lines draws a vertical line from each open folder along its items.

Icons#

icons="folder" shows a folder (open or closed) and a file icon before the text.

File explorer#

icons="file-type" also picks the icon of a file by its extension: code, markup, styles, data, text and images. An item’s icon overrides it.

Plus and minus icons#

toggle-icon="plus-minus" shows plus and minus instead of the chevron.

Selection#

value is the id of the selected item; selecting another one fires wds-change. Folders are not selected. An item with disabled (here public) cannot be selected or expanded.

Selected: page-tsx

API References#

wds-tree#

Tree: a hierarchy of folders and items (WAI-ARIA Tree View pattern), such as a file explorer or nested navigation. Pass the items in items; a folder expands and collapses on click and with the arrow keys, an item is selected on click or with Enter.

Attributes

AttributeTypeDefaultDescription
expandedstring[][]The ids of the expanded folders (in HTML a space-separated list).
valuestring''The id of the selected item; '' when none is selected. Folders are not selected: a click toggles them.
indentnumber20Indentation of each level in pixels.
toggle-icon.toggleIconWdsTreeToggleIcon'chevron'Icon that expands and collapses a folder.
iconsWdsTreeIcons'none'Icons before the text: folder shows folders and files, file-type also the kind of file by its extension.
linesbooleanfalseVertical lines that connect the items of a folder.
labelstring''Accessible name of the tree (aria-label).

Properties

PropertyDescription
itemsWdsTreeItem[]The items at the top level. Each item with children is a folder.

Events

EventDescription
wds-toggleCustomEvent<WdsTreeToggleDetail>The user expanded or collapsed a folder.
wds-changeCustomEvent<WdsTreeChangeDetail>The user selected an item.

Methods

MethodDescription
expandAll()Expands every folder.
collapseAll()Collapses every folder.

CSS parts (::part)

PartDescription
treeThe list of items (role="tree").
itemAn item (role="treeitem").
labelThe visible row of an item: toggle icon, icon and text.

CSS custom properties

PropertyDescription
--wds-tree-line-colorColor of the lines (default --wds-border).
--wds-tree-folder-colorColor of the folder icons.

Accessibility#

Screen reader#

The tree has role="tree" named by label. Items are treeitem elements with aria-level, aria-setsize and aria-posinset, so screen readers announce the depth and the position in the folder.

Folders have aria-expanded; other items aria-selected. A disabled item has aria-disabled and is skipped by clicks but stays in the arrow key order.

Icons are decorative (aria-hidden): the text of an item is its name.

Keyboard support#

KeyFunction
TabMoves focus into the tree, to the selected item or the first one. The tree is one tab stop.
ArrowDownMoves focus to the next visible item.
ArrowUpMoves focus to the previous visible item.
ArrowRightExpands a closed folder; in an open folder moves focus to its first item.
ArrowLeftCollapses an open folder; otherwise moves focus to the parent folder.
HomeMoves focus to the first item.
EndMoves focus to the last visible item.
EnterSelects the item, or expands or collapses the folder.
SpaceSelects the item, or expands or collapses the folder.
*Expands all folders on the level of the focused item.
A–ZMoves focus to the next item whose name starts with the typed letters.
Footer