Skip to main content

Tree

Hierarchical tree view with expandable nodes.

Usage

<w-tree label="File browser">
<w-slot item name="folder1" expandable>
<div>
<span>Documents</span>
<w-slot item name="file1"><div>Report.pdf</div></w-slot>
<w-slot item name="file2"><div>Notes.txt</div></w-slot>
</div>
</w-slot>
<w-slot item name="folder2" expandable>
<div>
<span>Images</span>
<w-slot item name="img1"><div>Photo.jpg</div></w-slot>
</div>
</w-slot>
</w-tree>

Props

PropTypeDefaultDescription
valuestring""Selected item name
expandedstring""Comma-separated expanded item names
labelstring""Accessible label

Slots

SlotElementDescription
itemContainerTree item (use name, optionally expandable)

Events

EventDetailDescription
change{ value }Selection changed
expand{ item, expanded }Item expanded/collapsed

Keyboard

KeyAction
ArrowDownNext visible item
ArrowUpPrevious visible item
ArrowRightExpand or move to first child
ArrowLeftCollapse or move to parent
HomeFirst item
EndLast visible item
Enter / SpaceSelect item

Styling

w-tree w-slot[item] > * {
/* every tree item */
}

/* Expanded folder */
w-tree w-slot[item] > *[aria-expanded="true"] {
/* open */
}

/* Selected item */
w-tree w-slot[item] > *[aria-selected="true"] {
background: #eef2ff;
}

/* Indent by depth — aria-level is set automatically */
w-tree w-slot[item] > *[aria-level="2"] {
padding-left: 1rem;
}
w-tree w-slot[item] > *[aria-level="3"] {
padding-left: 2rem;
}
SelectorTargets
w-tree w-slot[item] > *[aria-selected="true"]Selected item
w-tree w-slot[item] > *[aria-expanded="true"]Expanded folder
w-tree w-slot[item] > *[aria-level="N"]Items at depth N

Accessibility

  • Container has role="tree"
  • Items have role="treeitem" with aria-level
  • Expandable items have aria-expanded
  • aria-selected for selection state