Tree View
The VdTree component renders hierarchical data as an expandable/collapsible tree. Supports checkbox selection with parent-child cascade and initial open state — all driven by the :nodes prop plus the boolean checkbox / cascade props.
Basic File Tree
src
public
package.json
README.md
Checkbox Tree with Cascade
Permissions
Initially Open Nodes
Set "open": true on any node in the JSON data to expand it on render.
Documentation
- Getting Started
- Installation
- Getting Started Guide
- Configuration
- API Reference
- Examples
Generated HTML Structure
The component generates the following DOM structure from the JSON data. You can style each part using the CSS classes listed in the API reference.
<!-- Rendered structure (VdTree + recursive VdTreeNode) -->
<div class="vd-tree" role="tree">
<li class="vd-tree-node is-open" role="treeitem" aria-expanded="true">
<div class="vd-tree-node-content">
<button type="button" class="vd-tree-toggle" aria-label="Toggle"></button>
<input type="checkbox" class="vd-tree-checkbox" aria-label="Parent Node" />
<span class="vd-tree-icon ph ph-folder"></span>
<span class="vd-tree-label" tabindex="-1">Parent Node</span>
</div>
<ul class="vd-tree-children" role="group">
<li class="vd-tree-node" role="treeitem">
<div class="vd-tree-node-content">
<span class="vd-tree-toggle-placeholder"></span>
<span class="vd-tree-label" tabindex="-1">Leaf Node</span>
</div>
</li>
</ul>
</li>
</div>API Reference
Usage
<script setup lang="ts">
import { VdTree } from "@vanduo-oss/vd3";
const nodes = [
{ id: 'src', label: 'src', icon: 'ph ph-folder', children: [
{ id: 'btn', label: 'Button.vue', icon: 'ph ph-file-vue' },
]},
];
</script>
<template>
<VdTree :nodes="nodes" checkbox cascade />
</template>CSS Classes
| Class | Description |
|---|---|
.vd-tree | Auto-generated root container for the tree |
.vd-tree-node | Individual tree node <li> (renders .is-open when expanded) |
.vd-tree-node-content | The clickable row wrapper (toggle + icon + label) |
.vd-tree-toggle | Expand/collapse <button> for branch nodes |
.vd-tree-toggle-placeholder | Spacer that aligns leaf nodes with branch toggles |
.vd-tree-icon | Optional file/folder icon span before the label |
.vd-tree-label | Text label of the node |
.vd-tree-checkbox | Checkbox input rendered next to each node when the checkbox prop is set |
.vd-tree-children | Child <ul> wrapper around nested VdTreeNode items (collapsed/expanded via CSS) |
Node Object Shape
| Property | Type | Description |
|---|---|---|
id | string? | Optional unique identifier for the node (falls back to label or index) |
label | string? | Display text and checkbox aria-label |
icon | string? | CSS class(es) for an icon (e.g. "ph ph-folder") |
open | boolean? | If true, branch node renders expanded (.is-open) on init |
checked | boolean? | Initial or reactive checked state when checkbox mode is enabled |
children | TreeNode[]? | Nested child nodes (makes this a branch node) |
Component API
| Prop / event / method | Description |
|---|---|
:nodes | TreeNode[] — hierarchical array of { id?, label?, icon?, open?, checked?, children? }. |
:checkbox / :cascade | boolean — render checkboxes on every node; cascade (default true) propagates parent check changes to all descendants. |
:animated | boolean (default true) — smooth height expansion animation on node open/close using Fibonacci timing. |
VdTreeNode (:node, :checkbox, @toggle, @check) | Recursive child component used internally by VdTree and exported from @vanduo-oss/vd3 for custom tree compositions. |
tree:check / tree:toggle | Native CustomEvents bubbling from the root element (detail shapes documented below). |
ref.getChecked() | Exposed method — returns string[] of checked node ids (or labels). |
Events
| Event | Description |
|---|---|
tree:check | Fired on the element when a checkbox changes. event.detail contains { checked: string[], node: string | undefined } |
tree:toggle | Fired when a node is expanded or collapsed. event.detail contains { id: string | undefined, open: boolean } |
Accessibility
- The root container has
role="tree"; eachVdTreeNoderenders a<li role="treeitem">and wraps child lists in<ul role="group">. - Branch nodes set
aria-expanded="true"or"false"to reflect open state, and toggle buttons carryaria-label="Toggle". - Keyboard navigation on the tree: ArrowDown and ArrowUp move focus between visible node rows; ArrowRight expands a closed branch node; ArrowLeft collapses an open branch node.
- Native
<button class="vd-tree-toggle">and<input type="checkbox" class="vd-tree-checkbox">controls support Enter and Space activation with:aria-label="node.label"on checkboxes.