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

Update SvgIcon for the latest axe-core #540

Merged
merged 4 commits into from
Aug 2, 2021
Merged

Update SvgIcon for the latest axe-core #540

merged 4 commits into from
Aug 2, 2021

Conversation

ahuth
Copy link
Contributor

@ahuth ahuth commented Jul 28, 2021

Summary:

This PR

  • Updates axe-core to 4.3.2
  • Uses aria-hidden instead of presentation="role" for presentational/decorative icons (will explain more below)
  • Replaces the role prop with type purpose (will explain more below)

Wat, why?

Grab a cup of coffee (or your flavored beverage of choice) and let me tell you the story of why I made all these changes 📖

Chapter 1 - More upgrades, more problems

All I wanted to do was update axe-core (213e146), but that caused some axe testing failures. Looks like axe-core's allowlist of elements that can have role="presentation" does not include <svg>.

I can't find any documentation anywhere that svg elements shouldn't have that role. So I don't really agree that it should be forbidden.

Chapter 2 - Embrace the tools

But mdn has some interesting docs on when to use aria-hidden vs presentation="role", and our use case for icons seems closer to aria-hidden to me (completely remove from the accessibility tree).

So I changed SvgIcon to use aria-hidden when they're presentational/decorative (2e7650f).

Chapter 3 - Words have meaning, I think

An interesting ramification of that is now the role prop is decoupled from what actually happens on the HTML svg element. Meaning, role="presentation" would no longer result in the svg element literally having that role.

So I got to thinking (always dangerous) why not embrace that decoupling? And I renamed the prop from role to purpose (thank you Diedra for the prop name idea), and changed its possible values to "informative" and "decorative" (f226bd5).

Those words may still be kind of fuzzy, but they could better indicate the purpose of them. An "informative" icon has information to communicate. A decorative one is for decoration - it's extraneous.

If you've made it this far, you can tell I'm way over-analyzing this. But over-analyzing is half the fun.

Test Plan:

  • CI
  • Local storybook testing

@ahuth ahuth requested a review from a team July 28, 2021 23:05
@ahuth ahuth force-pushed the ah-upgrade-axe-core branch 2 times, most recently from e9444b1 to f226bd5 Compare July 29, 2021 00:30
@codecov
Copy link

codecov bot commented Jul 29, 2021

Codecov Report

Merging #540 (aadd789) into main (9ad182b) will decrease coverage by 0.03%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #540      +/-   ##
==========================================
- Coverage   91.10%   91.07%   -0.04%     
==========================================
  Files          21       21              
  Lines         281      280       -1     
  Branches       81       81              
==========================================
- Hits          256      255       -1     
  Misses         14       14              
  Partials       11       11              
Impacted Files Coverage Δ
src/SvgIcon/SvgIcon.tsx 90.00% <0.00%> (ø)
src/Button/button.stories.tsx 100.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9ad182b...aadd789. Read the comment docs.

@ahuth
Copy link
Contributor Author

ahuth commented Jul 29, 2021

Don't know why codecov thinks there's -0.04% less test coverage.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

size-limit report

Path Size
components 12.71 KB (+1.43% 🔺)
styles 3.81 KB (0%)

Comment on lines 77 to 81
children: (
<>
Link with icon <CheckCircle type="decorative" />
</>
),
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for updating this! That heart icon looked seriously fugly 😅

Comment on lines +105 to 106
<svg {...svgCommonProps} role="img">
<title>{props.title}</title>
Copy link
Contributor

Choose a reason for hiding this comment

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

I kinda wonder if we should use an aria-label and drop the role + title for informative icons for consistency. It feels a little weird to me that one version of the svgs has a role and the other doesn't. 🤷

Copy link
Contributor

Choose a reason for hiding this comment

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

One benefit of <title> (which our auditors request sometimes) is it'll appear when hovering on the icon, in case it's not clear what an icon means. I do generally like aria-label better, but that could be a reason to keep this

Copy link
Contributor

@dierat dierat left a comment

Choose a reason for hiding this comment

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

Weird that it doesn't allow role="presentation" on svgs, but I agree that aria-hidden makes more sense anyway.

Re: the API change, I think it would be a little misleading to have consumers pass in a role that won't actually result in a role attribute on the element, but I also feel like type is really vague. Maybe something like "purpose"? I also like the idea of switching from "img" to "informative" and from "presentation" to "decorative" because I think that will make it easier for people to reason about which category any particular icon falls into.

Copy link
Contributor

@anniehu4 anniehu4 left a comment

Choose a reason for hiding this comment

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

also like "informative" & "decorative"! I'm actually not against keeping the prop named "role", unless you're worried it'll cause confusion around the "role" prop for accessibility (I'd guess people haven't internalized that one so much)

@ahuth
Copy link
Contributor Author

ahuth commented Aug 2, 2021

Good point that type is really vague. Both role and purpose make a lot of sense.

I'll change it to purpose to deconflict with the HTML attribute. I don't think a conflict there is really a big problem, but for some reason "purpose" seems to go better with "informative"/"decorative" to me 🤔

ahuth added 3 commits August 2, 2021 12:36
Instead of the presentation role. After upgrading axe-core, we're now
getting failures for presentation not being a valid role for <svg>
elements.

I'm not 100% sure that's the case. But we can see that axe-core has an
allowlist for what elements can have that role [1], and svg is not on
it.

There doesn't seem to be documentation anywhere that it's explicitly not
allowed. But this change has the same effect, and plays nicely with axe.

Also, MDN lists some interesting differences between role="presentation"
and aria-hidden [2]. aria-hidden is for literally hiding something from
assistive technology, while role="presentation" only strips an element
of any semantics. Hiding it in this case seems reasonable and what we
actually intend.

1. https://github.com/dequelabs/axe-core/blob/2777dbc20c028d88a906e49a3c
   d7032b482f0988/lib/commons/aria/index.js#L1462-L1488
2. https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_
   Techniques/Using_the_aria-hidden_attribute
Instead of "img" and "presentation". Now that we're using aria-hidden
instead of role="presentation", our "role" prop is decoupled from the
actual HTML attributes anyway. I figured we may as well complete the
decoupling and not even pretend anymore like we're using an HTML/ARIA
role.

The names "informative" and "decorative" also may better indicate their
use cases.
@ahuth ahuth force-pushed the ah-upgrade-axe-core branch from f226bd5 to 2d165c0 Compare August 2, 2021 20:00
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

size-limit report

Path Size
components 14.47 KB (+1.37% 🔺)
styles 3.81 KB (0%)

"kind" is kind of generic, and "purpose" better describes the... purpose... of the prop.
@ahuth ahuth force-pushed the ah-upgrade-axe-core branch from 2d165c0 to aadd789 Compare August 2, 2021 20:08
@ahuth
Copy link
Contributor Author

ahuth commented Aug 2, 2021

Thanks! Merging (not sure what's up with codecov)

@ahuth ahuth merged commit 4b1ae50 into main Aug 2, 2021
@ahuth ahuth deleted the ah-upgrade-axe-core branch August 2, 2021 20:21
@ahuth
Copy link
Contributor Author

ahuth commented Sep 8, 2021

FYI, since dequelabs/axe-core#3124 axe will now allow svg elements to have role="presentation". I think our current implementation is still fine (or maybe even better).

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.

3 participants