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
  • package.json
  • README.md
  • Checkbox Tree with Cascade
    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
  • 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

    ClassDescription
    .vd-treeAuto-generated root container for the tree
    .vd-tree-nodeIndividual tree node <li> (renders .is-open when expanded)
    .vd-tree-node-contentThe clickable row wrapper (toggle + icon + label)
    .vd-tree-toggleExpand/collapse <button> for branch nodes
    .vd-tree-toggle-placeholderSpacer that aligns leaf nodes with branch toggles
    .vd-tree-iconOptional file/folder icon span before the label
    .vd-tree-labelText label of the node
    .vd-tree-checkboxCheckbox input rendered next to each node when the checkbox prop is set
    .vd-tree-childrenChild <ul> wrapper around nested VdTreeNode items (collapsed/expanded via CSS)

    Node Object Shape

    PropertyTypeDescription
    idstring?Optional unique identifier for the node (falls back to label or index)
    labelstring?Display text and checkbox aria-label
    iconstring?CSS class(es) for an icon (e.g. "ph ph-folder")
    openboolean?If true, branch node renders expanded (.is-open) on init
    checkedboolean?Initial or reactive checked state when checkbox mode is enabled
    childrenTreeNode[]?Nested child nodes (makes this a branch node)

    Component API

    Prop / event / methodDescription
    :nodesTreeNode[] — hierarchical array of { id?, label?, icon?, open?, checked?, children? }.
    :checkbox / :cascadeboolean — render checkboxes on every node; cascade (default true) propagates parent check changes to all descendants.
    :animatedboolean (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:toggleNative CustomEvents bubbling from the root element (detail shapes documented below).
    ref.getChecked()Exposed method — returns string[] of checked node ids (or labels).

    Events

    EventDescription
    tree:checkFired on the element when a checkbox changes. event.detail contains { checked: string[], node: string | undefined }
    tree:toggleFired when a node is expanded or collapsed. event.detail contains { id: string | undefined, open: boolean }
    Accessibility
    • The root container has role="tree"; each VdTreeNode renders 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 carry aria-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.