third_party/aria-practices/src/content/patterns/treeview/examples/treeview-navigation.html
Before considering use of the Tree View Pattern for site navigation, it is important to understand:
tree role requires implementation of complex functionality that is not needed for typical site navigation that is styled to look like a tree with expandable sections.The below example demonstrates how the Tree View Pattern can be used to build a navigation tree for a set of hierarchically organized web pages. It illustrates navigation of a mythical university web site that is comparable to the navigation illustrated in the Example Disclosure Navigation Menu. As noted above, the disclosure pattern is better suited for most web sites because few sites need the additional keyboard functionality required to support the ARIA tree role.
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 Example Using Declared Properties.
Similar examples include:
An important aspect of designing a navigation tree experience is the behavior of keyboard focus when an item in the tree is activated. If activating a tree item changes content on the page without triggering a browser page load, i.e., works like typical single-page apps, the focus position after the content load significantly affects efficiency for keyboard and assistive technology users. Accessible navigation trees typically implement one of the following two behaviors:
aria-current to the currently focused tree item informs screen reader users that navigation is complete and confirms the destination. This behavior is appropriate when common or important use case scenarios assume users are likely to need to peruse content from multiple nodes in the tree before deciding to interact with the loaded content. Note: screen reader users will need to navigate to the content to read it. In some cases, it might be possible to help screen reader users more quickly perceive the nature of the loaded content without navigating to it by referencing a portion of the content with an aria-describedby attribute on the tree item.The example on this page illustrates the first technique of focusing the level one heading in the newly loaded content.
nav element that has an aria-label that matches the label on the tree.aria-current="page" attribute is applied to the item in the tree associated with the currently displayed page.aria-current is also the only item with tabindex="0". That is, when tabbing into the tree, focus always lands on the item representing the current page.currentcolor value for the fill and stroke properties of the SVG polygon element is used to synchronize the color with text content. If specific colors are used to specify the fill and stroke properties, these colors will remain the same in high contrast mode, which could lead to insufficient contrast between the icon and the background or even make the icon invisible if its color matches the high contrast mode background.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 Tree View Pattern.
| Key | Function |
|---|---|
| Enter | |
| or Space |
h1 element in the newly loaded content. Note: Moving focus is optional behavior. Please read the above accessibility feature sections for details.| | 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 |
|---|---|---|---|
banner | header |
header element would typically not need role="banner" attribute to define the landmark, but in this example the header element is not in the proper scope of the body element to identify is as a banner landmark, so it must be explicitly identified using the role attribute.|
| navigation | | nav | Identifies the region containing the navigation tree. |
| | aria-label="navigation label" | nav | The aria-label attribute provides an accessible name for the navigation landmark. |
| region | | section |
main landmark, but since the page containing this example already has a main landmark, this section is identified using the region landmark.|
| | aria-labelledby="IDREFs" | section | The aria-labelledby attribute provides an accessible name for the region landmark by concatenating the website and page titles. |
| contentinfo | role="contentinfo" | footer |
footer element would typically not need role="contentinfo" attribute to define the landmark, but in this example the footer element is not in the proper scope of the body element to identify is as a contentinfo landmark, so it must be explicitly identified using the role attribute.|
| Role | Attribute | Element | Usage |
|---|---|---|---|
tree | ul |
ul element as a tree widget.|
| | aria-label="Mythical University" | ul | Provides an accessible name for the tree. |
| treeitem | | a | Identifies the element as a treeitem. |
| | tabindex="-1" | a |
treeitem role 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" | a |
treeitem role in the tab sequence.treeitem in the tree has tabindex="0".tabindex="0" is always on the treeitem with aria-current="page".|
| | aria-current="page" | a |
treeitem that is the link to the currently displayed page.treeitem with aria-current is a vertical bar to the left of the treeitem label.|
| | aria-expanded="false" | a |
treeitem elements that are parent nodes, i.e., they have aria-owns referencing a ul with role group.|
| | aria-expanded="true" | a |
treeitem elements that are parent nodes, i.e., they have aria-owns referencing a ul with role group.|
| | aria-owns="IDREF" | a | Refers to the element with role group that contains the set of child treeitem elements that belong to this parent treeitem. |
| 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.|
| none | | li |
listitem role of the li element from assistive technologies.listitem is required to be contained by a list, but the containing element is no longer a list; it is a tree or a group.listitem semantic from the browser's accessibility tree eliminates the potential for confusing rendering by assistive technologies.|
To copy the following HTML code, please open it in CodePen.