third_party/aria-practices/src/content/patterns/treeview/treeview-pattern.html
A tree view widget presents a hierarchical list. Any item in the hierarchy may have child items, and items that have children may be expanded or collapsed to show or hide the children. For example, in a file system navigator that uses a tree view to display folders and files, an item representing a folder can be expanded to reveal the contents of the folder, which may be files, folders, or both.
When using a keyboard to navigate a tree, a visual keyboard indicator informs the user which item is focused. If the tree allows the user to choose just one item for an action, then it is known as a single-select tree. In some implementations of single-select tree, the focused item also has a selected state; this is known as selection follows focus. However, in multi-select trees, which enable the user to select more than one item for an action, the selected state is always independent of the focus. For example, in a typical file system navigator, the user can move focus to select any number of files for an action, such as copy or move. It is important that the visual design distinguish between items that are selected and the item that has focus. For more details, see this description of differences between focus and selection and Deciding When to Make Selection Automatically Follow Focus.
aria-level, aria-posinset and aria-setsize based on DOM structure.aria-level, aria-posinset and aria-setsize.aria-level, aria-posinset and aria-setsize based on DOM structure.Terms for describing tree views include:
NodeAn item in a tree.Root NodeNode at the base of the tree; it may have one or more child nodes but does not have a parent node.Child NodeNode that has a parent; any node that is not a root node is a child node.End NodeNode that does not have any child nodes; an end node may be either a root node or a child node.Parent Node Node with one or more child nodes. It can be open (expanded) or closed (collapsed). Open NodeParent node that is expanded so its child nodes are visible.Closed NodeParent node that is collapsed so the child nodes are not visible.
For a vertically oriented tree:
When a single-select tree receives focus:
When a multi-select tree receives focus:
Right arrow:
Left arrow:
Down Arrow: Moves focus to the next node that is focusable without opening or closing a node.
Up Arrow: Moves focus to the previous node that is focusable without opening or closing a node.
Home: Moves focus to the first node in the tree without opening or closing a node.
End: Moves focus to the last node in the tree that is focusable without opening a node.
Enter: activates a node, i.e., performs its default action. For parent nodes, one possible default action is to open or close the node. In single-select trees where selection does not follow focus (see note below), the default action is typically to select the focused node.
Type-ahead is recommended for all trees, especially for trees with more than 7 root nodes:
* (Optional): Expands all siblings that are at the same level as the current node.
Selection in multi-select trees: Authors may implement either of two interaction models to support multiple selection: a recommended model that does not require the user to hold a modifier key, such as Shift or Control, while navigating the list or an alternative model that does require modifier keys to be held while navigating in order to avoid losing selection states.
Recommended selection model -- holding a modifier key while moving focus is not necessary:
Alternative selection model -- Moving focus without holding the Shift or Control modifier unselects all selected nodes except for the focused node:
tree role supports the aria-activedescendant property, which provides an alternative to moving DOM focus among treeitem elements when implementing keyboard navigation. For details, see Managing Focus in Composites Using aria-activedescendant.All tree nodes are contained in or owned by an element with role tree.
Each element serving as a tree node has role treeitem.
Each root node is contained in the element with role tree or referenced by an aria-owns property set on the tree element.
Each parent node contains or owns an element with role group.
Each child node is contained in or owned by an element with role group that is contained in or owned by the node that serves as the parent of that child.
Each element with role treeitem that serves as a parent node has aria-expanded set to false when the node is in a closed state and set to true when the node is in an open state. End nodes do not have the aria-expanded attribute because, if they were to have it, they would be incorrectly described to assistive technologies as parent nodes.
If the tree supports selection of more than one node, the element with role tree has aria-multiselectable set to true. Otherwise, aria-multiselectable is either set to false or the default value of false is implied.
The selection state of each selectable node is indicated with either aria-selected or aria-checked:
aria-selected, then aria-checked is not specified for any nodes. Alternatively, if the selection state is indicated with aria-checked, then aria-selected is not specified for any nodes. See notes below regarding considerations for which property to use and for details of the unusual conditions that might allow for both properties in the same tree.true. No more than one node is selected at a time if the element with role tree does not have aria-multiselectable set to true.false.The element with role tree has either a visible label referenced by aria-labelledby or a value specified for aria-label.
If the complete set of available nodes is not present in the DOM due to dynamic loading as the user moves focus in or scrolls the tree, each node has aria-level, aria-setsize, and aria-posinset specified.
If the tree element is horizontally oriented, it has aria-orientation set to horizontal. The default value of aria-orientation for a tree is vertical.
aria-selected or aria-checked are:aria-selected for single-select widgets and aria-checked for multi-select widgets. In the absence of factors that would make an alternative convention more appropriate, this is a recommended convention.aria-selected and aria-checked are extremely rare. It is strongly recommended to avoid designing a tree widget that would have the need for more than one type of state. If both states were to be used within a tree, all the following conditions need to be satisfied:aria-selected is different from the meaning and purpose of aria-checked in the user interface.