Treeview

3 Treeview variations from the W3C ARIA Authoring Practices Guide.

Treeview (File Directory, Computed)

A file chooser whose nested treeitem/group structure lets the browser compute hierarchy metadata. Selection is separate from keyboard focus.

Corresponding W3C APG example

Example

Project files

  • Projects
    • architecture.md
    • release-notes.md

Keyboard interaction

Up/Down moves through visible items. Right expands a branch or enters it; Left collapses it or returns to its parent. Home/End moves to the first/last visible item. Type letters to find a name; * expands sibling branches. Enter/Space activates an item. Click a branch arrow to expand it. Activating a name selects it without changing expansion.

Events

Listen on the widget or delegate to <axxy-scope> or document. All custom events bubble.

  • axxy-tree-select — Dispatched when a tree item is activated. (target: [role="tree"], detail: { item: HTMLElement, label: string })
  • axxy-tree-toggle — Dispatched when a tree branch expands or collapses. (target: Tree item, detail: { item: HTMLElement, expanded: boolean })

Events reference and examples

Example HTML

<axxy-scope>
  <h2 id="demo-files-label">Project files</h2>
  <ul role="tree" aria-labelledby="demo-files-label">
    <li role="treeitem"  aria-expanded="true">
      <span class="tree-expander" aria-hidden="true">▸</span>
      Projects
      <ul>
        <li role="treeitem">architecture.md</li>
        <li role="treeitem">release-notes.md</li>
        <li role="treeitem" aria-expanded="false">
          <span class="tree-expander" aria-hidden="true">▸</span>
          Website
          <ul>
            <li role="treeitem">index.html</li>
            <li role="treeitem">styles.css</li>
          </ul>
        </li>
      </ul>
    </li>
    <li role="treeitem" aria-expanded="false">
      <span class="tree-expander" aria-hidden="true">▸</span>
      Reports
      <ul>
        <li role="treeitem">accessibility.pdf</li>
        <li role="treeitem">usage.csv</li>
      </ul>
    </li>
    <li role="treeitem" aria-expanded="false">
      <span class="tree-expander" aria-hidden="true">▸</span>
      Letters
      <ul>
        <li role="treeitem">welcome.txt</li>
        <li role="treeitem">thank-you.txt</li>
      </ul>
    </li>
  </ul>
  <label for="demo-file-viewer">Selected file or folder</label>
  <input id="demo-file-viewer" readonly value="Nothing selected">
</axxy-scope>

Treeview (File Directory, Declared)

A file chooser with explicit hierarchy metadata. Selection is separate from keyboard focus; activating a file or folder updates the viewer.

Corresponding W3C APG example

Example

Project files

  • Projects
    • architecture.md
    • release-notes.md

Keyboard interaction

Up/Down moves through visible items. Right expands a branch or enters it; Left collapses it or returns to its parent. Home/End moves to the first/last visible item. Type letters to find a name; * expands sibling branches. Enter/Space activates an item. Click a branch arrow to expand it. Activating a name selects it without changing expansion.

Events

Listen on the widget or delegate to <axxy-scope> or document. All custom events bubble.

  • axxy-tree-select — Dispatched when a tree item is activated. (target: [role="tree"], detail: { item: HTMLElement, label: string })
  • axxy-tree-toggle — Dispatched when a tree branch expands or collapses. (target: Tree item, detail: { item: HTMLElement, expanded: boolean })

Events reference and examples

Example HTML

<axxy-scope>
  <h2 id="demo-files-label">Project files</h2>
  <ul role="tree" aria-labelledby="demo-files-label">
    <li role="treeitem" aria-level="1" aria-setsize="3" aria-posinset="1" aria-expanded="true">
      <span class="tree-expander" aria-hidden="true">▸</span>
      Projects
      <ul>
        <li role="treeitem">architecture.md</li>
        <li role="treeitem">release-notes.md</li>
        <li role="treeitem" aria-expanded="false">
          <span class="tree-expander" aria-hidden="true">▸</span>
          Website
          <ul>
            <li role="treeitem">index.html</li>
            <li role="treeitem">styles.css</li>
          </ul>
        </li>
      </ul>
    </li>
    <li role="treeitem" aria-expanded="false">
      <span class="tree-expander" aria-hidden="true">▸</span>
      Reports
      <ul>
        <li role="treeitem">accessibility.pdf</li>
        <li role="treeitem">usage.csv</li>
      </ul>
    </li>
    <li role="treeitem" aria-expanded="false">
      <span class="tree-expander" aria-hidden="true">▸</span>
      Letters
      <ul>
        <li role="treeitem">welcome.txt</li>
        <li role="treeitem">thank-you.txt</li>
      </ul>
    </li>
  </ul>
  <label for="demo-file-viewer">Selected file or folder</label>
  <input id="demo-file-viewer" readonly value="Nothing selected">
</axxy-scope>

Treeview (Navigation)

A navigation tree with real page links. The current page is revealed automatically and becomes the entry point whenever focus leaves the tree.

Corresponding W3C APG example

Keyboard interaction

Up/Down moves through visible items. Right expands a branch or enters it; Left collapses it or returns to its parent. Home/End moves to the first/last visible item. Type letters to find a name; * expands sibling branches. Enter/Space activates an item. Links open their destinations. Category buttons expand or collapse branches. Tab leaves the tree.

Events

Listen on the widget or delegate to <axxy-scope> or document. All custom events bubble.

  • axxy-tree-select — Dispatched when a tree item is activated. (target: [role="tree"], detail: { item: HTMLElement, label: string })
  • axxy-tree-toggle — Dispatched when a tree branch expands or collapses. (target: Tree item, detail: { item: HTMLElement, expanded: boolean })

Events reference and examples

Example HTML

<axxy-scope>
  <nav aria-label="Tree examples">
    <ul role="tree" aria-label="Tree examples">
      <li>
        <a role="treeitem" href="/examples/">All examples</a>
      </li>
      <li>
        <button role="treeitem" aria-expanded="true">
          <span class="tree-expander" aria-hidden="true">▸</span>
          Tree views
        </button>
        <ul>
          <li>
            <a role="treeitem" href="/examples/treeview/#treeview-navigation" aria-current="page">Navigation tree</a>
          </li>
          <li>
            <a role="treeitem" href="/examples/treeview/#treeview-1a">Computed file tree</a>
          </li>
          <li>
            <a role="treeitem" href="/examples/treeview/#treeview-1b">Declared file tree</a>
          </li>
        </ul>
      </li>
    </ul>
  </nav>
</axxy-scope>