third_party/aria-practices/src/content/patterns/treeview/examples/treeview-1a.html
The following example implementation of the Tree View Pattern simulates a widget for selecting a file or folder from within a hierarchical file system for viewing in a file viewer. In the My Documents tree, each parent node represents a folder and each end node represents a file. Activating a node selects the node and puts the name of the folder or file in the read-only edit field that represents the file viewer.
This example relies on the browser to compute values for aria-setsize, aria-posinset, and aria-level. The ARIA specification for these properties states that browsers can, but are not required to, compute their values. So, some browser and assistive technology combinations may not compute or report correct position and level information if it is not explicitly declared. If testing reveals gaps in support for these properties, override automatic computation by explicitly declaring their values as demonstrated in the example of a File Directory Treeview using declared properties.
Similar examples include:
Projects
project-1.docx
project-2.docx
Project 3
project-4.docx
Project 5
Reports
report-1
report-2
report-3
Letters
letter-1
letter-2
letter-3
File or Folder Selected:
To make the focus indicator easier to see, nodes in the tree have custom focus and hover styling created using CSS focus and hover pseudo-classes.
A tree item that can be expanded to reveal child items is called a parent node. It is a closed node when the children are hidden and an open node when it is expanded. An end node does not have any children. For a complete list of terms and definitions, see the Treeview Pattern.
Note that in this example, selection and focus are distinct; moving focus does not change which node is selected. Because selection does not follow focus, keyboard and screen reader users can navigate and explore the tree without changing the content of the file viewer. To learn more about this aspect of the design, see Deciding When to Make Selection Automatically Follow Focus.
| Key | Function |
|---|---|
| Enter | Performs the default action, which is to select the node, causing the name of the node to appear in the File or Folder Selected textbox. |
| Space | Performs the default action, which is to select the node, causing the name of the node to appear in the File or Folder Selected textbox. |
| Down arrow |
| | Up arrow |
| | Right Arrow |
| | Left Arrow |
| | Home | Moves focus to first node without opening or closing a node. | | End | Moves focus to the last node that can be focused without expanding any nodes that are closed. | | a-z, A-Z |
| | * (asterisk) |
|
| Role | Attribute | Element | Usage |
|---|---|---|---|
tree | ul |
ul element as a tree widget.|
| | aria-labelledby="ID_REFERENCE" | ul | Refers to the heading element that contains the label that identifies the purpose of the tree. |
| treeitem | | li | Identifies the element as a treeitem. |
| | tabindex="-1" | li |
treeitem element focusable without including it in the tab sequence of the page.treeitem elements are focusable, but only one is included in the tab sequence.|
| | tabindex="0" | li |
treeitem element in the tab sequence.treeitem in the tree has tabindex="0".treeitem in the tree is included in the tab sequence when the page loads.tree, the element included in the tab sequence changes to the element with focus as described in Managing Focus Within Components Using a Roving tabindex.|
| | aria-expanded="false" | li |
treeitem elements that are parent nodes, i.e., they contain a ul with the group role.|
| | aria-expanded="true" | li |
treeitem elements that are parent nodes, i.e., they contain a ul with the group role.|
| | aria-selected="false" | li |
treeitem elements.|
| | aria-selected="true" | li |
treeitem elements.|
| group | | ul |
ul element as a container of treeitem elements that form a branch of the tree.treeitem.aria-level, aria-setsize and aria-posinset values for the nodes contained in the branch.|
To copy the following HTML code, please open it in CodePen.