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
TreeView: Implement arrow key navigation #2331
Conversation
Co-authored-by: Eric Bailey <ericwbailey@users.noreply.github.com>
π¦ Changeset detectedLatest commit: 574d2c8 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
size-limit report π¦
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very exciting! Everything is looking good, but we don't want Space to call onSelect
or expand a parent node. We're reserving that for when/if we have nodes that can be checked or unchecked.
For future reference, check Primer's documentation on tree view accessibility, before the W3C's tree view APG. I worked with @jscholes and the a11y team to suss out what the APG gets "wrong" and define improved patterns.
I skimmed the implementation and mostly focused on testing the UI. I can look closer at the code once @ericwbailey gives his β on the keyboard navigation.
Is it expected that none of the "links" in File Tree With Directory Links do anything when they're clicked or you press "Enter" when focused on them? |
@colebemis @mperrotti should loading items in the tree be focusable? Or should aria-activedescendant skip over them? |
@jdrush89 We'll want only one focusable node for loading node(s), with an announcement that indicates how many loading nodes are present (if we know). More granular behavior to follow in the second round of TreeView API work. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approval assumes @ericwbailey also approves.
) | ||
} | ||
|
||
// DOM utilities used for focus management |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non-blocking nitpicks:
- Would it make more sense to move these to a utilities file instead of keeping them in
TreeView.tsx
? - Should these functions have their own unit tests? Or do we think the TreeView tests are sufficient?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Would it make more sense to move these to a utilities file instead of keeping them in TreeView.tsx?
Yeah, it might make sense to pull this out into a hook later. I'm going to keep it all in the same file for now so I can iterate more quickly
- Should these functions have their own unit tests? Or do we think the TreeView tests are sufficient?
I'd like to avoid testing implementation details like this because we'd need to update lots of tests if we decide to change the underlying implementation (even if we don't change behavior). I think the "Keyboard interactions" unit tests give us solid coverage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've just tested this in VoiceOver and NVDA and it's looking/sounding great! Amazing stuff π
Summary
Adds support for arrow key navigation of a TreeView using
aria-activedescendant
(based on the TreeView API spec).π Try it out
CleanShot.2022-09-15.at.15.39.38.mp4
Impact
This PR will enable keyboard and screen reader users to navigate a TreeView.
VoiceOver demo
Screen.Recording.2022-09-15.at.3.51.06.PM.mov
Test cases
Here are the test cases I wrote for the TreeView keyboard interactions (based on the ARIA spec):
Reviewers
I'm open to feedback about any part of the implementation but specifically, I'd love confirmation that the keyboard and screen reader behavior work as expected.
Merge checklist