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

WB-1636: Add describedBy prop to announce the popover dialog contents to screen readers. #2110

Closed
wants to merge 3 commits into from

Conversation

jandrade
Copy link
Member

Summary:

The Popover dialog element is not assigning correctly the aria-describedby
value, thus causing Screen Readers not being able to read the popover contents
correctly.

The current implementation is trying to reference aria-describedby to the
anchor/trigger element (or button that triggers the popover to open/close). This
is incorrect, as the aria-describedby value should reference to a particular
content inside the dialog itself.

This PR adds a new prop to the Popover component, describedBy, which will
allow the user to pass a string referencing the element that contains the
dialog's contents. This will allow Screen Readers to read the popover contents
correctly.

Issue: https://khanacademy.atlassian.net/browse/WB-1636

Test plan:

  1. Navigate to /?path=/story/popover-popover--described-by.
  2. Open the Popover.
  3. Verify that the Screen Reader reads the title of the Popover dialog.
  4. Change the describedBy prop to reference the content element by changing the
    describedBy prop to content control in the Storybook.
  5. Now verify that the SR reads the contents of the Popover dialog.

@jandrade jandrade self-assigned this Nov 10, 2023
Copy link

changeset-bot bot commented Nov 10, 2023

🦋 Changeset detected

Latest commit: 9306f8a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@khanacademy/wonder-blocks-popover Minor

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

Copy link
Contributor

github-actions bot commented Nov 10, 2023

Size Change: +84 B (0%)

Total Size: 92.8 kB

Filename Size Change
packages/wonder-blocks-accordion/dist/es/index.js 3.67 kB +7 B (0%)
packages/wonder-blocks-popover/dist/es/index.js 4.41 kB +77 B (+2%)
ℹ️ View Unchanged
Filename Size
packages/wonder-blocks-banner/dist/es/index.js 1.53 kB
packages/wonder-blocks-birthday-picker/dist/es/index.js 1.72 kB
packages/wonder-blocks-breadcrumbs/dist/es/index.js 1.13 kB
packages/wonder-blocks-button/dist/es/index.js 4.26 kB
packages/wonder-blocks-cell/dist/es/index.js 2.19 kB
packages/wonder-blocks-clickable/dist/es/index.js 3.24 kB
packages/wonder-blocks-color/dist/es/index.js 1.15 kB
packages/wonder-blocks-core/dist/es/index.js 3.67 kB
packages/wonder-blocks-data/dist/es/index.js 6.33 kB
packages/wonder-blocks-dropdown/dist/es/index.js 12 kB
packages/wonder-blocks-form/dist/es/index.js 5.34 kB
packages/wonder-blocks-grid/dist/es/index.js 1.36 kB
packages/wonder-blocks-i18n/dist/es/index.js 4.54 kB
packages/wonder-blocks-icon-button/dist/es/index.js 3.06 kB
packages/wonder-blocks-icon/dist/es/index.js 3.04 kB
packages/wonder-blocks-labeled-field/dist/es/index.js 72 B
packages/wonder-blocks-layout/dist/es/index.js 1.88 kB
packages/wonder-blocks-link/dist/es/index.js 2.54 kB
packages/wonder-blocks-modal/dist/es/index.js 5.04 kB
packages/wonder-blocks-pill/dist/es/index.js 1.03 kB
packages/wonder-blocks-progress-spinner/dist/es/index.js 1.51 kB
packages/wonder-blocks-search-field/dist/es/index.js 1.55 kB
packages/wonder-blocks-spacing/dist/es/index.js 158 B
packages/wonder-blocks-switch/dist/es/index.js 2.06 kB
packages/wonder-blocks-testing/dist/es/index.js 3.94 kB
packages/wonder-blocks-theming/dist/es/index.js 1.21 kB
packages/wonder-blocks-timing/dist/es/index.js 1.78 kB
packages/wonder-blocks-toolbar/dist/es/index.js 862 B
packages/wonder-blocks-tooltip/dist/es/index.js 5.05 kB
packages/wonder-blocks-typography/dist/es/index.js 1.49 kB

compressed-size-action

Copy link

codecov bot commented Nov 10, 2023

Codecov Report

Merging #2110 (9306f8a) into main (6b8bf8d) will increase coverage by 0.00%.
Report is 3 commits behind head on main.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #2110   +/-   ##
=======================================
  Coverage   97.07%   97.07%           
=======================================
  Files         243      243           
  Lines       28245    28286   +41     
  Branches     2466     2420   -46     
=======================================
+ Hits        27418    27459   +41     
  Misses        827      827           
Files Coverage Δ
...-blocks-popover/src/components/popover-content.tsx 99.38% <100.00%> (+0.03%) ⬆️
...r-blocks-popover/src/components/popover-dialog.tsx 99.32% <100.00%> (+<0.01%) ⬆️
...s/wonder-blocks-popover/src/components/popover.tsx 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes


Continue to review full report in Codecov by Sentry.

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

Copy link
Contributor

github-actions bot commented Nov 10, 2023

A new build was pushed to Chromatic! 🚀

https://5e1bf4b385e3fb0020b7073c-zocviyfbxy.chromatic.com/

Chromatic results:

Metric Total
Captured snapshots 321
Tests with visual changes 1
Total stories 394
Inherited (not captured) snapshots [TurboSnap] 0
Tests on the build 321

Copy link
Contributor

@timmcca-be timmcca-be left a comment

Choose a reason for hiding this comment

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

Thanks so much for looking at this!! One extra consideration: I wonder how we can make this work with PopoverContentCore too

@@ -233,12 +253,12 @@ export default class Popover extends React.Component<Props, State> {
{(props: PopperElementProps) => (
<PopoverDialog
{...props}
aria-describedby={`${uniqueId}-anchor`}
aria-describedby={`${uniqueId}-${describedBy}`}
Copy link
Contributor

Choose a reason for hiding this comment

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

So it looks like this existing aria-describedby prop makes it so the popover is described by the content that it is pointing at. I think it would be best not to totally remove that, as we want some way to tie the popover to the content it points at. Adobe's react-aria-components library uses aria-labelledby for this, so maybe a solution would be:

Suggested change
aria-describedby={`${uniqueId}-${describedBy}`}
aria-labelledby={`${uniqueId}-anchor`}
aria-describedby={`${uniqueId}-${describedBy}`}

Copy link
Member Author

Choose a reason for hiding this comment

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

In this case pointing labelledby to the anchor element would not work as we expect. If we make that, then the dialog would be announced with the contents of the button/anchor element and the intention would be to use that to announce the dialog title instead.

From: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/dialog_role#associated_aria_roles_states_and_properties

aria-labelledby
Use this attribute to label the dialog. Often, the value of the aria-labelledby attribute will be the id of the element used to title the dialog.

That makes me think that we can even use that instead of the describedBy solution. Let me try that alternative.

* when it is opened.
* Defaults to "title".
*/
describedBy: "title" | "content" | "all-content";
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
describedBy: "title" | "content" | "all-content";
describedBy: "title" | "content" | "title-and-content";

I think this is slightly clearer

@jandrade
Copy link
Member Author

jandrade commented Dec 5, 2023

Closed as we are going with a different approach added in #2134

@jandrade jandrade closed this Dec 5, 2023
@jandrade jandrade deleted the popover-sr branch December 9, 2024 20:25
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.

2 participants