third_party/aria-practices/src/content/patterns/treegrid/examples/treegrid-1.html
The following example demonstrates how the Treegrid Pattern can be used to make an interactive tree that enables users to both navigate the hierarchical structure of email conversations and also navigate elements that describe each email, such as subject and sender.
Similar examples include:
This example demonstrates three different ways of implementing the keyboard navigation specified in the treegrid pattern. The following links change the behavior of the navigation keys:
Note: A row-only option is not provided. A treegrid where cells cannot be focused would be implemented as a tree view. A treeview that has columns in its visual presentation may be appropriate when all the following conditions are present:
| Subject | Summary | |
|---|---|---|
| Treegrids are awesome | Want to learn how to use them? | [email protected] |
| re: Treegrids are awesome | I agree with you, they are the shizzle | [email protected] |
| re: Treegrids are awesome | They are great for showing a lot of data, like a grid | [email protected] |
| re: Treegrids are awesome | Cool, we've been needing an example and documentation | [email protected] |
| re: Treegrids are awesome | I hear the Fancytree library is going to align with this example! | [email protected] |
| re: Treegrids are awesome | Sometimes they are more like trees, others are more like grids | [email protected] |
| re: Treegrids are awesome | Cool, when it's a tree, let's keep left/right to collapse/expand | [email protected] |
| re: Treegrids are awesome | I see, sometimes right arrow moves by column | [email protected] |
NOTE: The following table includes descriptions of how keyboard commands move focus among cells and rows in the treegrid implementation on this page. In the example on this page, some cells contain a single focusable widget, and if a cell contains a widget, the cell is not focusable; the widget receives focus instead of the cell. So, when a keyboard command description says a command moves focus to a cell, the command may either focus the cell or a widget inside the cell.
| Key | Function |
|---|---|
| Right Arrow |
| | Left Arrow |
| | Down Arrow |
| | Up Arrow |
| | Tab |
| | Shift + Tab |
| | Home |
| | End |
| | Control + Home |
| | Control + End |
| | Enter |
|
| Role | Attribute | Element | Usage |
|---|---|---|---|
treegrid | table | Identifies the element as a treegrid. | |
aria-label="Inbox" | table | Provides an accessible name for the treegrid. | |
row | tr |
row.row role is not an implicit semantic for the tr element when in a treegrid.|
| | tabindex="-1" | tr or td |
row and gridcell elements are focusable, but only one is included in the tab sequence.|
| | tabindex="0" | tr or td |
row or gridcell in the treegrid has tabindex="0".row in the treegrid is included in the tab sequence when the page loads.treegrid, the element included in the tab sequence changes to the element with focus as described in the practice for Managing Focus Within Components Using a Roving tabindex.|
| | aria-expanded="false" | tr or td |
aria-expanded is on the tr elements, but when the treegrid is configured to support focus on cells only, aria-expanded is on the first td element contained in each row.|
| | aria-expanded="true" | tr or td |
aria-expanded is on the tr elements, but when the treegrid is configured to support focus on cells only, aria-expanded is on the first td element contained in each row.|
| | aria-level="number" | tr |
|
| | aria-setsize="number" | tr | Defines the number of rows in the set of rows that are in the same branch and at the same level within the hierarchy. |
| | aria-posinset="number" | tr |
|
| gridcell | | td |
gridcell.gridcell role is not an implicit semantic for the td element when in a treegrid.|
NOTE: Due to an error in the ARIA 1.1 specification, the aria-posinset and aria-setsize properties are not supported on row elements. This is being corrected in ARIA 1.2. Consequently, when validating the HTML in this example, errors are generated.
To copy the following HTML code, please open it in CodePen.