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.
Example
Project files
- Projects
- architecture.md
- release-notes.md
- Website
- index.html
- styles.css
- Reports
- accessibility.pdf
- usage.csv
- Letters
- welcome.txt
- thank-you.txt
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 })
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.
Example
Project files
- Projects
- architecture.md
- release-notes.md
- Website
- index.html
- styles.css
- Reports
- accessibility.pdf
- usage.csv
- Letters
- welcome.txt
- thank-you.txt
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 })
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>