Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Accessibility Support #163

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Neurrone
Copy link

@Neurrone Neurrone commented Aug 4, 2019

Fixes #162

See the commit for implementation details. I also had to temporarily disable scss-lint, since I don't have it installed.

Outstanding items:

  • Figure out why styling is broken

@Neurrone
Copy link
Author

Neurrone commented Aug 4, 2019

Looks like the CI is failing due to my hack in the gulp script; will remove that commit before merging.

@Neurrone Neurrone force-pushed the accessibility-improvements branch 3 times, most recently from 85296b6 to 619c85b Compare August 9, 2019 17:33
@Neurrone
Copy link
Author

Neurrone commented Aug 9, 2019

Force pushed to updated inaccurate comments and commit messages to reflect that focus computations are done via a pre-order traversal of the tree, not an in-order one.

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
@jakezatecky
Copy link
Owner

I am sorry about the radio silence. I will get to looking at this soon (ideally within a few days).

@Neurrone
Copy link
Author

@jakezatecky any chance you could take a look?

@jakezatecky jakezatecky added this to the v1.7.0 milestone Jan 22, 2020
@Neurrone
Copy link
Author

Ping @jakezatecky

@jakezatecky jakezatecky modified the milestones: v1.7.0, v1.8.0 Jun 8, 2021
jakezatecky added a commit that referenced this pull request Mar 15, 2023
Make the underlying native checkboxes more accessible to screen readers and touch.

Resolves #276. Addresses parts of #163.

Co-Authored-By: Dickson Tan <16471962+Neurrone@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Accessibility support
2 participants