File Directory Treeview Example Using Declared Properties
The below example implements the Treeview Design Pattern to simulate a file selector. When users activate an item that represents a file name in the below tree, the name of the selected file appears in the read-only edit field next to the tree.
The code in this example explicitly declares values for aria-setsize
, aria-posinset
and aria-level
, which overrides browser computation of values for these properties.
The ARIA 1.0 specification for these properties states that browsers can, but are not required to, compute these values.
Similar examples include:
- File Directory Treeview using computed properties
- Navigation Treeview using computed properties
- Navigation Treeview using declared properties
Example
File Viewer
-
Projects
- project-1.docx
- project-2.docx
-
project-3
- project-3A.docx
- project-3B.docx
- project-3C.docx
- project-4.docx
-
project-5
- project-5A.docx
- project-5B.docx
- project-5C.docx
- project-5D.docx
- project-5E.docx
- project-5F.docx
-
Reports
-
report-1
- report-1A.docx
- report-1B.docx
- report-1C.docx
-
report-2
- report-2A.docx
- report-2B.docx
- report-2C.docx
- report-2D.docx
-
report-3
- report-3A.docx
- report-3B.docx
- report-3C.docx
- report-3D.docx
-
report-1
-
Letters
-
letter-1
- letter-1A.docx
- letter-1B.docx
- letter-1C.docx
-
letter-2
- letter-2A.docx
- letter-2B.docx
- letter-2C.docx
- letter-2D.docx
-
letter-3
- letter-3A.docx
- letter-3B.docx
- letter-3C.docx
- letter-3D.docx
-
letter-1
Accessibility Features
To make the focus indicator easier to see, nodes in the tree have a custom focus and hover styling created using CSS focus and hover pseudo-classes.
Terms Used to Describe Trees
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 Design Pattern.
Keyboard Support
Key | Function |
---|---|
Enter or Space |
|
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, Property, State, and Tabindex Attributes
Role | Attribute | Element | Usage |
---|---|---|---|
tree |
ul |
|
|
aria-labelledby="IDREF" |
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 |
|
|
tabindex="0" |
li |
|
|
aria-expanded="false" |
li |
|
|
aria-expanded="true" |
li |
|
|
aria-setsize="number" |
li |
Defines the number of treeitem elements in the set of treeitem elements that are in the same branch and at the same level within the hierarchy. |
|
aria-posinset="number" |
li |
|
|
aria-level="number" |
li |
|
|
group |
ul |
|
Javascript and CSS Source Code
- CSS: tree.css
- Javascript: tree.js
- Javascript: treeitem.js
- Javascript: treeitemClick.js
HTML Source Code