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

Tooltip: add aria-describedby to anchor only if not redundant #65989

Merged
merged 6 commits into from
Oct 10, 2024

Conversation

ciampo
Copy link
Contributor

@ciampo ciampo commented Oct 9, 2024

What?

Related to #65888

This PR makes changes to the Tooltip component so that the aria-describedby attribute gets added more conservatively

Why?

As discussed in #65888, the way Tooltip adds an aria-describedby attribute can disrupt assistive technology users:

  • the tooltip is displayed dynamically, which means that the accessible description is only available when the tooltip is visible;
  • the tooltip's description can override an existing description;
  • the tooltip's description can be unnecessary if it's a copy of the accessible label;
  • in general, tooltips should not be a mean of adding an accessible description (although this drawback is not in the scope of this PR)

How?

Implementing @t-hamano 's suggestion: the Tooltip component checks that there isn't a aria-describedby attribute already defined, and that the tooltip text is different from the anchor's accessible label.

Testing Instructions

  • Make sure that a tooltip anchor has an explicit aria-describedby attribute. Inspecting the anchor, make sure that the aria-describedby attribute doesn't change when the tooltip is shown.
  • Make sure that a tooltip anchor has an explicit aria-label attribute, and that the tooltip text is the same as the anchor's aria-label. Inspecting the anchor, make sure that the aria-describedby attribute is not added to the anchor when the tooltip is shown.

I've added a couple of temporary Storybook examples to help with testing in isolation.

In the editor, you can test this by:

  • inserting a block
  • moving focus to the block toolbar
  • inspect the button responsible for triggering the "options" dropdown (the last one in the toolbar)
  • notice how, with the changes from this PR applied, when the button receives focus and the tooltip shows, the button does not get an aria-describedby attribute added for the tooltip

Screenshots or screencast

Kapture.2024-10-09.at.16.31.29.mp4

Copy link
Member

@tyxla tyxla left a comment

Choose a reason for hiding this comment

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

Code-wise this looks good to me 👍 I think it's a good compromise, considering we'll seek a better long-term fix.

Leaving the potential approval to @afercia after confirming it resolves the problem.

packages/components/src/tooltip/index.tsx Show resolved Hide resolved
@afercia
Copy link
Contributor

afercia commented Oct 9, 2024

Thanks for working at this fix. I don't have bandwidth to test it now but as long as:

  • It prevents the double announcement of label and description that have the same value.
  • It prevents from dynamically updating existing aria-describedby value

then I'd think it's a reasonable short-term solution until the root problem gets solved. Thanks!

@ciampo
Copy link
Contributor Author

ciampo commented Oct 9, 2024

I'll add a couple of unit tests and temporary storybook examples to validate the thesis further

@ciampo ciampo force-pushed the fix/tooltip-aria-describedby branch from a2e7c44 to 4345c49 Compare October 9, 2024 14:56
@ciampo ciampo added [Type] Bug An existing feature does not function as intended [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). [Package] Components /packages/components labels Oct 9, 2024
@ciampo ciampo requested review from tyxla and a team October 9, 2024 14:58
@ciampo ciampo marked this pull request as ready for review October 9, 2024 14:58
@ciampo ciampo requested a review from ajitbohra as a code owner October 9, 2024 14:58
Copy link

github-actions bot commented Oct 9, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: ciampo <[email protected]>
Co-authored-by: tyxla <[email protected]>
Co-authored-by: t-hamano <[email protected]>
Co-authored-by: afercia <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@ciampo
Copy link
Contributor Author

ciampo commented Oct 9, 2024

Added unit tests, a couple of temporary Storybook examples, and updated PR description.

Let's give this PR a round of review and merge if it improves the current situation for the 6.7 release.

@ciampo ciampo requested review from t-hamano and afercia October 9, 2024 14:59
@ciampo ciampo force-pushed the fix/tooltip-aria-describedby branch from 4345c49 to 7ea28ad Compare October 9, 2024 16:15
Copy link
Contributor

@t-hamano t-hamano left a comment

Choose a reason for hiding this comment

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

LGTM!

I tested screen readers primarily on the post editor and site editor, and there were no issues with double reading of labels or inappropriate reading of descriptions.

Here is an example of that test:

Block Toolbar

block-toolbar.mp4

Header and Sidebar

2d9840e9931d4d7b8d9d3cc9fd47f0e7.mp4

@ciampo ciampo force-pushed the fix/tooltip-aria-describedby branch from 7ea28ad to 7048449 Compare October 10, 2024 12:23
@ciampo ciampo enabled auto-merge (squash) October 10, 2024 12:23
@ciampo ciampo added the Backport to WP 6.7 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Oct 10, 2024
@ciampo
Copy link
Contributor Author

ciampo commented Oct 10, 2024

Thank you for the reviews!

Enabled auto-merging + backporting to WordPress 6.7 release

@ciampo ciampo disabled auto-merge October 10, 2024 12:34
@ciampo ciampo enabled auto-merge (squash) October 10, 2024 12:36
@ciampo ciampo merged commit b06549d into trunk Oct 10, 2024
63 checks passed
@ciampo ciampo deleted the fix/tooltip-aria-describedby branch October 10, 2024 13:13
@github-actions github-actions bot added this to the Gutenberg 19.5 milestone Oct 10, 2024
@github-actions github-actions bot removed the Backport to WP 6.7 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Oct 10, 2024
gutenbergplugin pushed a commit that referenced this pull request Oct 10, 2024
* Improve comment

* Add unit tests

* Add temporary storybook examples

* CHANGELOG

* Fix lint errors

* Remove temporary storybook examples

---

Co-authored-by: ciampo <[email protected]>
Co-authored-by: tyxla <[email protected]>
Co-authored-by: t-hamano <[email protected]>
Co-authored-by: afercia <[email protected]>
@github-actions github-actions bot added the Backported to WP Core Pull request that has been successfully merged into WP Core label Oct 10, 2024
Copy link

I just cherry-picked this PR to the wp/6.7 branch to get it included in the next release: 1fdd5d9

@DaniGuardiola
Copy link
Contributor

Thanks @ciampo! We should look into removing the patch next, which I believe you created a draft PR for somewhere else. I will look at everything once I'm back from sick leave.

@ciampo
Copy link
Contributor Author

ciampo commented Oct 13, 2024

We should look into removing the patch next, which I believe you created a draft PR for somewhere else. I will look at everything once I'm back from sick leave.

Yup, see #66021

ciampo added a commit that referenced this pull request Oct 14, 2024
* Improve comment

* Add unit tests

* Add temporary storybook examples

* CHANGELOG

* Fix lint errors

* Remove temporary storybook examples

---

Co-authored-by: ciampo <[email protected]>
Co-authored-by: tyxla <[email protected]>
Co-authored-by: t-hamano <[email protected]>
Co-authored-by: afercia <[email protected]>
karthick-murugan pushed a commit to karthick-murugan/gutenberg that referenced this pull request Nov 13, 2024
…ess#65989)

* Improve comment

* Add unit tests

* Add temporary storybook examples

* CHANGELOG

* Fix lint errors

* Remove temporary storybook examples

---

Co-authored-by: ciampo <[email protected]>
Co-authored-by: tyxla <[email protected]>
Co-authored-by: t-hamano <[email protected]>
Co-authored-by: afercia <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backported to WP Core Pull request that has been successfully merged into WP Core [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). [Package] Components /packages/components [Type] Bug An existing feature does not function as intended
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

5 participants