-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. The keyboard can now be used to move through the tree, expand and collapse nodes: * Home / end moves to the first and last visible node, respectively. * Up / down arrows moves to the previous / next visible node. * Right arrow expands a collapsed node, if focus is on a collapsed parent. If focus is on an expanded parent, move to its first child. * Left arrow collapses the node if focus is on an expanded parent. Otherwise, focus is moved to the parent of the currently focused node. * First letter navigation: for example, press R to move focus to the next node who's label starts with R. * Space toggles selection, as expected for a checkbox. This is implemented by computing an pre-order traversal of visible nodes updated each render which greatly simplifies computation for focus movements. Focus is managed by using the [roving tabindex pattern](https://www.w3.org/TR/wai-aria-practices-1.1/#kbd_roving_tabindex). * Each TreeNode takes in a new property, `hasFocus` which is initialized to `false` on initial render. This causes each tree item to have `tabindex=-1` set, which excludes them from tab order, but allows them to be programatically focused. * On initial focus of the top-level `CheckboxTree` component, we initialize the currently focused node index to 0. This causes the first tree node's `hasFocus` to be set to `true`, which sets `tabIndex=0`, so it is included in tab order. `TreeNode`'s `componentDidUpdate` fires a focus event when it is supposed to gain focus. * Other key presses manipulate the currently focused index, which causes the element with `tabindex=0` to move about, hence the roving tabindex. 2. Add the necessary aria attributes for screen readers to correctly read the state of the tree, whether a node is expanded/collapsed, checked etc. For more information, see https://www.w3.org/TR/wai-aria-practices-1.1/#TreeView
- Loading branch information
Showing
5 changed files
with
188 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters