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

fix(material/tree): Apply aria-level to all nodes #17818

Merged
merged 6 commits into from Aug 6, 2020

Conversation

martiansnoop
Copy link
Contributor

Previously, only leaf nodes had aria-level applied.

This is an incremental change since this is an unfamiliar codebase for
me. The main benefit it will have on its own is that it will allow
anyone doing custom dom manipulation to know what level the node is on.
Otherwise by itself there is no change in how NVDA reads nodes with
children. (It currently reads them as literally "grouping"; no
information about the contents is provided).

This change will be necessary for a later change I'm planning, wherein
the role of parent nodes will be changed from "group" to "treeitem", in
accordance with how roles are applied in WAI-ARIA reference examples
such as
https://www.w3.org/TR/wai-aria-practices/examples/treeview/treeview-1/treeview-1b.html

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Nov 26, 2019
@martiansnoop
Copy link
Contributor Author

I've tested this manually via the demos on http://localhost:4200/tree, but I'm having trouble finding the unit tests to update.

@crisbeto
Copy link
Member

You can find the tests here and here. You can run them with yarn bazel test //src/material/tree:unit_tests_chromium-local and yarn bazel test //src/cdk/tree:unit_tests_chromium-local.

@martiansnoop
Copy link
Contributor Author

martiansnoop commented Nov 26, 2019

Thank you! 🤦‍♂️ I was looking for files ending in _test.ts and my eyes went right past the .spec.ts files.

I located the related tests, but it appears like all of the nodes were already leaf nodes (only leaf nodes have role="treeitem"), so the current set of test changes did pass before the changes to mat-tree/cdk-tree were applied.

I haven't looked into modifying the dataset to have a deeper tree yet (and I'm not sure that kind of change belongs in this commit) -- thoughts? [EDIT: it looks like adding items to the tree is really easy, so I think I'll just do that in this PR.]

EDIT: It appears that, as demonstrated by the CdkTree tests, that client code has control over what the level of the nodes are. Since the specific value is not relevant to this change, I just changed the assertions to match the level specified by the data object, but that concerns me slightly in that the next change I have queued up involves making the leveling start at 0 instead of 1.

@jelbourn jelbourn added the G This is is related to a Google internal issue label Nov 27, 2019
@jelbourn
Copy link
Member

Definitely an oversight that there aren't any existing aria-level tests. The best thing would be to add a new test (with either a new or existing test component) that asserts the right aria-level behavior.

@jelbourn jelbourn added Accessibility This issue is related to accessibility (a11y) P2 The issue is important to a large percentage of users, with a workaround labels Nov 27, 2019
@martiansnoop martiansnoop force-pushed the mat-tree-a11y branch 2 times, most recently from 3cf38db to 04cc369 Compare November 27, 2019 01:18
@martiansnoop
Copy link
Contributor Author

Thanks! Currently I still need to clean up an unrelated change and also figure out why the mat-tree version of the test is failing, so not quite ready for review.

@martiansnoop
Copy link
Contributor Author

I think I may have found a bug in the flat tree tests:

  1. It seems like the code in the expectFlatTreeToMatch function was not asserting that all of the expected values were present in the tree, just that all the dom nodes matched an expected value. I added that assertion and a few of the existing tests fail for me: 312471c
  2. When items are added to the data source (like here), they do not seem to be reflected in the DOM yet
  3. Tests where a child node was added (example) were passing erroneously because of 1.

I need some help figuring out what to do to get the nodes into the DOM (would have guessed detectChanges would have been doing that). Once that gets figured out, I'll fix the tests that were broken by adding the tree length assertion and put that into a separate CL (unless the owners prefer it in this one).

@jelbourn
Copy link
Member

Hey, I somehow missed the notification on this PR; sorry for the super delayed response.

I took a look your test issue. You're correctly adding a new child node, but its parent is marked as collapsed, so the new node isn't rendering. You can fix it by adding component.treeControl.expandAll(); before the detectChanges.

This definitely wasn't obvious- it took me like 10 minutes to realize what was happening.

@martiansnoop martiansnoop force-pushed the mat-tree-a11y branch 4 times, most recently from 36321bd to b0d9885 Compare February 10, 2020 00:43
@martiansnoop
Copy link
Contributor Author

Aha, thank you! I think everything passes now.

Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jelbourn jelbourn added pr: lgtm action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release labels Feb 10, 2020
@martiansnoop
Copy link
Contributor Author

Do I need to take any actions to merge this?

@jelbourn
Copy link
Member

jelbourn commented Mar 9, 2020

I bumped the priority on this in our merge queue- it looks like it got overlooked due to being older

@mmalerba mmalerba removed the action: merge The PR is ready for merge by the caretaker label Apr 6, 2020
@jelbourn
Copy link
Member

From a quick glance it seems like the bindings should just all be level + 1 (with corresponding test updates), since the spec uses 1-based indexing for some reason.

@jelbourn jelbourn added this to PRs in P2 PRs Jul 9, 2020
@andrewseguin
Copy link
Contributor

@martiansnoop We can try to get this in - did you get a chance to see the message about level + 1 from @jelbourn?

@jelbourn
Copy link
Member

@annieyw added a commit to this PR to update the level to start at one. LGTM for new changes.

@jelbourn jelbourn added the action: merge The PR is ready for merge by the caretaker label Jul 21, 2020
src/material/tree/node.ts Outdated Show resolved Hide resolved
martiansnoop and others added 3 commits July 30, 2020 14:10
Previously, only leaf nodes had aria-level applied.

This is an incremental change since this is an unfamiliar codebase for
me. The main benefit it will have on its own is that it will allow
anyone doing custom dom manipulation to know what level the node is on.
Otherwise by itself there is no change in how NVDA reads nodes with
children. (It currently reads them as literally "grouping"; no
information about the contents is provided).

This change will be necessary for a later change I'm planning, wherein
the role of parent nodes will be changed from "group" to "treeitem", in
accordance with how roles are applied in WAI-ARIA reference examples
such as
https://www.w3.org/TR/wai-aria-practices/examples/treeview/treeview-1/treeview-1b.html
@annieyw annieyw force-pushed the mat-tree-a11y branch 3 times, most recently from def2a1b to 018dd3b Compare July 30, 2020 22:23
src/cdk/tree/tree.ts Outdated Show resolved Hide resolved
src/cdk/tree/tree.ts Outdated Show resolved Hide resolved
@andrewseguin andrewseguin removed the action: merge The PR is ready for merge by the caretaker label Jul 31, 2020
Copy link
Contributor

@mmalerba mmalerba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mmalerba mmalerba added action: merge The PR is ready for merge by the caretaker and removed lgtm labels Jul 31, 2020
@mmalerba mmalerba merged commit aeb6f89 into angular:master Aug 6, 2020
P2 PRs automation moved this from PRs to Done Aug 6, 2020
mmalerba pushed a commit that referenced this pull request Aug 6, 2020
* fix(material/tree): Apply aria-level to all nodes

Previously, only leaf nodes had aria-level applied.

This is an incremental change since this is an unfamiliar codebase for
me. The main benefit it will have on its own is that it will allow
anyone doing custom dom manipulation to know what level the node is on.
Otherwise by itself there is no change in how NVDA reads nodes with
children. (It currently reads them as literally "grouping"; no
information about the contents is provided).

This change will be necessary for a later change I'm planning, wherein
the role of parent nodes will be changed from "group" to "treeitem", in
accordance with how roles are applied in WAI-ARIA reference examples
such as
https://www.w3.org/TR/wai-aria-practices/examples/treeview/treeview-1/treeview-1b.html

* change aria-level binding to one-based

* change role to treeitem

* always set role to treeitem

* simplify logic for setting role

* add follow up TODO to makr role as deprecated

Co-authored-by: Annie Wang <annieyw@google.com>
(cherry picked from commit aeb6f89)
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Accessibility This issue is related to accessibility (a11y) action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement G This is is related to a Google internal issue P2 The issue is important to a large percentage of users, with a workaround target: patch This PR is targeted for the next patch release
Projects
P2 PRs
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

7 participants