Navigation Treeview Example Using Declared Properties
NOTE:: This example is recently revised and ready for review. Please provide feedback in issue 405.
The below example demonstrates how the Treeview Design Pattern can be used to build a navigation tree for a set of hierarchically organized web pages. In this example, the user can browse a set of pages about foods that is organized into categories. Activating an item in the tree will open a page about the chosen food.
Since a tree item is the only kind of interactive element that can be contained in a tree, links to web pages in a navigation tree have the treeitem
role.
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
- File Directory Treeview using declared properties
- Navigation Treeview using computed properties
Example
Foods
- Fruits
- Vegetables
-
Grains
- Cereal Grains
- Pseudocereal Grains
- Oilseeds
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 parrent 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 or a |
|
|
tabindex="-1" |
li or a |
|
|
tabindex="0" |
li or a |
|
|
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 |
|
|
none
|
li
|
|
Javascript and CSS Source Code
- CSS: treeLinks.css
- Javascript: treeLinks.js
- Javascript: treeitemLinks.js
HTML Source Code