File Directory Treeview Example Using Declared Properties
-About This Example
-
- 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.
-
- 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 specification for these properties states that browsers can, but are not required to, compute these values.
-
Similar examples include:
- -Example
-My Documents
-
@@ -153,307 +108,5 @@
Accessibility Features
-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.
-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 Tree View Pattern. -
-Keyboard Support
-- 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, read the guidance section about - 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 Selectedtextbox. |
-
| Space | -Performs the default action, which is to select the node, causing the name of the node to appear in the File or Folder Selectedtextbox. |
-
| 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="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 |
-
-
|
-
| - | tabindex="0" |
- li |
-
-
|
-
| - | aria-expanded="false" |
- li |
-
-
|
-
| - | aria-expanded="true" |
- li |
-
-
|
-
| - | aria-selected="false" |
- li |
-
-
|
-
| - | aria-selected="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
-To copy the following HTML code, please open it in CodePen.
- -
-
-
-