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

Add a11y support for the tree-control #36459

Merged
merged 10 commits into from Mar 2, 2023
Merged

Conversation

mdperez86
Copy link
Contributor

@mdperez86 mdperez86 commented Jan 16, 2023

Depends on #36590

All Submissions:

Changes proposed in this Pull Request:

Depends on #36480
Partialy closes #35851

  • This PR is a very minor change/addition and does not require testing instructions (if checked you can ignore/remove the next section).

How to test the changes in this Pull Request:

  1. Run storybook
  2. Visit http://localhost:6007/?path=/story/woocommerce-admin-experimental-treecontrol--selection-multiple
  3. This implementation follow the a11y guides described in https://www.w3.org/WAI/ARIA/apg/patterns/treeview/examples/treeview-navigation/.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you created a changelog file for each project being changed, ie pnpm --filter=<project> changelog add?

FOR PR REVIEWER ONLY:

  • I have reviewed that everything is sanitized/escaped appropriately for any SQL or XSS injection possibilities. I made sure Linting is not ignored or disabled.

@mdperez86 mdperez86 added focus: product management Related to product creation and editing. focus: new product ux revamped product management experience labels Jan 16, 2023
@mdperez86 mdperez86 requested a review from a team January 16, 2023 21:10
@mdperez86 mdperez86 self-assigned this Jan 16, 2023
@github-actions github-actions bot added the package: @woocommerce/components issues related to @woocommerce/components label Jan 16, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Jan 16, 2023

Test Results Summary

Commit SHA: ef34a9b

Test 🧪Passed ✅Failed 🚨Broken 🚧Skipped ⏭️Unknown ❔Total 📊Duration ⏱️
API Tests25900202610m 54s
E2E Tests189006019516m 0s

To view the full API test report, click here.
To view the full E2E test report, click here.
To view all test reports, visit the WooCommerce Test Reports Dashboard.

@mdperez86 mdperez86 marked this pull request as ready for review January 17, 2023 13:52
@mattsherman mattsherman assigned mattsherman and unassigned mdperez86 Jan 19, 2023
@mattsherman mattsherman mentioned this pull request Jan 24, 2023
7 tasks
@mattsherman mattsherman added the status: blocked The issue is blocked from progressing, waiting for another piece of work to be done. label Jan 24, 2023
@mattsherman mattsherman marked this pull request as draft February 1, 2023 19:58
@mattsherman mattsherman removed their assignment Feb 15, 2023
@AnnaMag AnnaMag marked this pull request as ready for review February 23, 2023 14:53
@octaedro octaedro requested review from octaedro and a team and removed request for a team and octaedro February 24, 2023 17:34
@mdperez86 mdperez86 self-assigned this Feb 28, 2023
@mdperez86 mdperez86 force-pushed the add/35851-tree-control-a11y branch from e5a813a to 7fd9f31 Compare March 1, 2023 17:42
@codecov
Copy link

codecov bot commented Mar 1, 2023

Codecov Report

Merging #36459 (ef34a9b) into trunk (ac47d18) will decrease coverage by 0.0%.
The diff coverage is 24.3%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             trunk   #36459     +/-   ##
==========================================
- Coverage     46.7%    46.7%   -0.0%     
- Complexity   17183    17188      +5     
==========================================
  Files          429      429             
  Lines        64799    64820     +21     
==========================================
  Hits         30251    30251             
- Misses       34548    34569     +21     
Impacted Files Coverage Δ
...ocommerce/includes/admin/class-wc-admin-assets.php 0.0% <0.0%> (ø)
...mmerce/includes/admin/class-wc-admin-importers.php 0.0% <0.0%> (ø)
plugins/woocommerce/includes/class-wc-ajax.php 4.3% <0.0%> (-0.1%) ⬇️
...s/Version1/class-wc-rest-coupons-v1-controller.php 42.9% <0.0%> (ø)
...rs/Version1/class-wc-rest-orders-v1-controller.php 46.2% <0.0%> (ø)
...rters/class-wc-product-csv-importer-controller.php 36.1% <28.6%> (ø)
.../includes/import/class-wc-product-csv-importer.php 74.9% <44.4%> (ø)
...s/Version2/class-wc-rest-coupons-v2-controller.php 94.7% <75.0%> (ø)
plugins/woocommerce/includes/class-wc-coupon.php 73.9% <100.0%> (ø)
...lugins/woocommerce/includes/class-wc-discounts.php 84.5% <100.0%> (ø)
... and 18 more

Copy link
Contributor

@nathanss nathanss left a comment

Choose a reason for hiding this comment

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

Nice job. It's testing well on the storybook and the aria attributes seem correct.

I'm just wondering if there wasn't a way of doing this without relying on CSS and DOM manipulation, but I don't have any suggestions regarding that, so I just left a small suggestion.

return null;
}

const step = {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can move this to outside the function as it's a constant

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I put it there because I intentionally wanted to hide the step variable from being used outside of that function.

But I don't have a strong opinion for this anyway. It's done now!

@mattsherman
Copy link
Contributor

I'm just wondering if there wasn't a way of doing this without relying on CSS and DOM manipulation, but I don't have any suggestions regarding that, so I just left a small suggestion.

@nathanss What specific CSS and DOM manipulation are you referring to?

Significance: minor
Type: dev

Add a11y support for the tree-control
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of tree-control, consider Tree component

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @mattsherman. It's done now.

@nathanss
Copy link
Contributor

nathanss commented Mar 1, 2023

@nathanss What specific CSS and DOM manipulation are you referring to?

@mattsherman I guess it's not "manipulation" since we're not changing the values, just querying them. I'm referring to all the document queries inside the use-keyboard on getFirstChild, getFirstAncestor, getAllHeadings, and getNextFocusableElement. It's pretty philosophical but it seems we do that a lot in our code instead of doing it the "React way". Am I making sense?

@mattsherman
Copy link
Contributor

@nathanss What specific CSS and DOM manipulation are you referring to?

@mattsherman I guess it's not "manipulation" since we're not changing the values, just querying them. I'm referring to all the document queries inside the use-keyboard on getFirstChild, getFirstAncestor, getAllHeadings, and getNextFocusableElement. It's pretty philosophical but it seems we do that a lot in our code instead of doing it the "React way". Am I making sense?

Thanks for the clarification. I can see how these DOM queries could be non-ideal, as if the rendered DOM were changed elsewhere in code, these queries would need to be changed.

What would a more "React way" look like to you?

currentHeading: HTMLDivElement
): NodeListOf< HTMLDivElement > | undefined {
const rootTree = currentHeading.closest< HTMLDivElement >(
'.experimental-woocommerce-tree--level-1'
Copy link
Contributor

Choose a reason for hiding this comment

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

Is that -1 here correct? Can't that number change depending on the situation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is that -1 here correct?

Yes it's. This --level-1 refers to the nesting level of the tree. So that all subtrees have their parent level + 1 like --level-2, --level-3 ... going from the root to the leafs.

@nathanss
Copy link
Contributor

nathanss commented Mar 2, 2023

What would a more "React way" look like to you?

@mattsherman I guess the main thing that CSS is solving in use-keyboard is fetching references to other Tree Items inside one of the Tree Items to focus them (and in some cases to expand and collapse through the useExpander hook). The alternative could be a shared context between tree items that would be able to update a state that would trigger the necessary changes based only on the tree data, instead of CSS.

For the focus, each tree item could have a useEffect hook that would focus itself based on some change in this context.

This could potentially make the performance worse. Maybe it's OK to rely on CSS a little bit, especially in a component's implementation. This all seems to be encapsulated inside the TreeControl, so at least we have full control of the CSS. To be fair I'm more accustomed to using react components instead of implementing them 😄

@mdperez86
Copy link
Contributor Author

What would a more "React way" look like to you?

@mattsherman I guess the main thing that CSS is solving in use-keyboard is fetching references to other Tree Items inside one of the Tree Items to focus them (and in some cases to expand and collapse through the useExpander hook). The alternative could be a shared context between tree items that would be able to update a state that would trigger the necessary changes based only on the tree data, instead of CSS.

For the focus, each tree item could have a useEffect hook that would focus itself based on some change in this context.

This could potentially make the performance worse. Maybe it's OK to rely on CSS a little bit, especially in a component's implementation. This all seems to be encapsulated inside the TreeControl, so at least we have full control of the CSS. To be fair I'm more accustomed to using react components instead of implementing them 😄

Yes that was my first approach, trying to use a context but the tree is a complex structure that we should use carefully. After trying to perform across tree-items operations thinks becomes heavy to manage. Like focusing the first child of an expanded subtree, or focus the first ancestor or successor, ... Also, the idea was to keep thinks scoped to each own custom hook so that we can replace them easily when needed, another reason why the hooks are very isolated. Well, if we could find a way to deal with all the scenarios without impacting performance, I'm definitely in!

Copy link
Contributor

@nathanss nathanss left a comment

Choose a reason for hiding this comment

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

I'm OK with the current code and it seems to work well, so I'm approving it

@mdperez86 mdperez86 merged commit 7dd3797 into trunk Mar 2, 2023
@mdperez86 mdperez86 deleted the add/35851-tree-control-a11y branch March 2, 2023 20:26
@github-actions github-actions bot added this to the 7.6.0 milestone Mar 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
focus: new product ux revamped product management experience focus: product management Related to product creation and editing. package: @woocommerce/components issues related to @woocommerce/components status: blocked The issue is blocked from progressing, waiting for another piece of work to be done.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Enhancement] Allow users to add items using keyboard
3 participants