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

[SR] Add aria labels to interactive Circle graph #1928

Merged
merged 12 commits into from
Dec 13, 2024
Merged

[SR] Add aria labels to interactive Circle graph #1928

merged 12 commits into from
Dec 13, 2024

Conversation

nishasy
Copy link
Contributor

@nishasy nishasy commented Nov 27, 2024

Summary:

Make the Circle interactive graph screen reader accessible as outlined by the Circle SRUX doc.

  • Add aria label, aria-described-by, and aria-live for the outer circle
  • Add aria label, aria-described-by, and aria-live for the radius point on the edge of the circle
  • Add all the label and description strings to the strings.ts file for translations later

Issue: https://khanacademy.atlassian.net/browse/LEMS-1706

Test plan:

@nishasy nishasy self-assigned this Nov 27, 2024
Copy link
Contributor

github-actions bot commented Nov 27, 2024

npm Snapshot: Published

Good news!! We've packaged up the latest commit from this PR (193facf) and published it to npm. You
can install it using the tag PR1928.

Example:

yarn add @khanacademy/perseus@PR1928

If you are working in Khan Academy's webapp, you can run:

./dev/tools/bump_perseus_version.sh -t PR1928

Copy link
Contributor

github-actions bot commented Nov 27, 2024

Size Change: +976 B (+0.08%)

Total Size: 1.27 MB

Filename Size Change
packages/perseus/dist/es/index.js 416 kB +554 B (+0.13%)
packages/perseus/dist/es/strings.js 4.12 kB +422 B (+11.41%) ⚠️
ℹ️ View Unchanged
Filename Size
packages/kas/dist/es/index.js 39 kB
packages/keypad-context/dist/es/index.js 760 B
packages/kmath/dist/es/index.js 4.27 kB
packages/math-input/dist/es/index.js 77.9 kB
packages/math-input/dist/es/strings.js 1.79 kB
packages/perseus-core/dist/es/index.js 1.48 kB
packages/perseus-editor/dist/es/index.js 688 kB
packages/perseus-linter/dist/es/index.js 22.2 kB
packages/pure-markdown/dist/es/index.js 3.66 kB
packages/simple-markdown/dist/es/index.js 12.5 kB

compressed-size-action

@nishasy nishasy marked this pull request as ready for review December 6, 2024 19:56
@nishasy nishasy marked this pull request as draft December 6, 2024 19:56
@khan-actions-bot khan-actions-bot requested a review from a team December 6, 2024 19:56
@khan-actions-bot
Copy link
Contributor

Gerald

Required Reviewers
  • @Khan/perseus for changes to .changeset/cool-bulldogs-dance.md, packages/perseus/src/strings.ts, packages/perseus/src/widgets/interactive-graphs/mafs-graph.test.tsx, packages/perseus/src/widgets/interactive-graphs/graphs/circle.tsx

Don't want to be involved in this pull request? Comment #removeme and we won't notify you of further changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, I don't think I can test the changes to the aria properties on update with jest. I don't even think I can test that the radius point's aria live value state updates when the circle is moved.

Someone please tell me if I'm wrong. I'm open to suggestions for how to test this stuff.

Copy link
Member

Choose a reason for hiding this comment

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

You should be able to use a command (can't remember it off the top of my head) where you fire onMove or move event and then you can use expect(aria-live value in element to be "polite").

It's worth a 15 min time box to see if this can be done.

Copy link
Member

Choose a reason for hiding this comment

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

This article might have what you're looking for, the tool is called fireEvent:
https://vinayak-hegde.medium.com/js-react-and-customevent-testing-using-jest-and-react-testing-library-abb247fd758a

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added tests!

@nishasy nishasy marked this pull request as ready for review December 10, 2024 02:26
@nishasy nishasy requested review from catandthemachines, anakaren-rojas and a team and removed request for a team December 10, 2024 02:35
Copy link
Member

@catandthemachines catandthemachines left a comment

Choose a reason for hiding this comment

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

Approved! If you can give the test one extra try to trigger a move event and then check that the aria-live changes. Other than that you look good. ❤️

Copy link
Member

Choose a reason for hiding this comment

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

You should be able to use a command (can't remember it off the top of my head) where you fire onMove or move event and then you can use expect(aria-live value in element to be "polite").

It's worth a 15 min time box to see if this can be done.

@@ -20,32 +21,6 @@ function expectLabelInDoc(label: string) {
expect(screen.getByLabelText(label)).toBeInTheDocument();
}

function getBaseMafsGraphProps(): MafsGraphProps {
Copy link
Member

Choose a reason for hiding this comment

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

Nice! Glad you moved this <3

@@ -37,31 +38,101 @@ function CircleGraph(props: CircleGraphProps) {
const {dispatch, graphState} = props;
const {center, radiusPoint} = graphState;

const {strings} = usePerseusI18n();
const [radiusPointAriaLive, setRadiusPointAriaLive] = React.useState<
"off" | "polite"
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd recommend using the aria live type in
packages/perseus/src/widgets/interactive-graphs/types.ts

</>
{/* Hidden elements to provide the descriptions for the
circle and radius point's `aria-describedby` properties. */}
<g id={radiusId} style={{display: "hidden"}}>
Copy link
Contributor

Choose a reason for hiding this comment

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

If I remember correctly, using display: "hidden" also hides it from the screen reader. Did you have any issues when testing this?
Using a11y.srOnly might be an alternative if you do have issues
packages/perseus/src/util/a11y.ts

Copy link
Contributor Author

@nishasy nishasy Dec 12, 2024

Choose a reason for hiding this comment

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

I used display: hidden because I don't want the screen reader (or any user) to ever actually access this element. It's only there for its text and ID so that other stuff can refer to it. It seemed to work fine in my manual tests, so I think this should be okay?

@nishasy nishasy merged commit 09d906c into main Dec 13, 2024
8 checks passed
@nishasy nishasy deleted the sr-circle branch December 13, 2024 00:13
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.

4 participants