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

feat(LEMS-1733): adds aria labels to line segment #2032

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

anakaren-rojas
Copy link
Contributor

@anakaren-rojas anakaren-rojas commented Dec 18, 2024

Summary:

  • Adds aria label and description to whole line segment graph
  • Adds copy that distinguishes between single line segment on a coordinate plane and multiple line segments on a coordinate plane
  • Adds aria label for individual end points of line segment

Issue: LEMS-1733

Test plan:

  1. Navigate to Chromatic
  2. Select Line Segment Interactive Graph from drop down
  3. Validate screen reader can read line segment

Expected behavior

Single Segment

  1. Screen reader reads aria label for whole graph: A line segment on a coordinate plane.
  2. Screen reader reads aria description for whole graph: A line segment on a coordinate plane. Endpoint 1 at ${point1X} comma ${point1Y}. Endpoint 2 ${point2X} comma ${point2Y}. Segment length %(length)s units.

Multiple Segments

  1. Screen reader reads aria label for whole graph: {Number of segments} segment on a coordinate plane.
  2. Screen reader reads aria description for whole graph: {Number of segments} segment on a coordinate plane. Segment {N}: Endpoint 1 at ${point1X} comma ${point1Y}. Endpoint 2 ${point2X} comma ${point2Y}. Segment length %(length)s units.

Individual Points

  1. When selected, screen reader reads aria label for end points: Endpoint ${endpointNumber} at ${x} comma ${y}
  2. When moving a point, aria labels and descriptions adjust to include new end points and length, as appropriate

Screenshots:

Single Segment on a Coordinate Plane - Aria Label and Description

image

Multiple segments on a coordinate plane - Aria Label and Description

image

Individual Segment Aria Label - Description

image

@anakaren-rojas anakaren-rojas self-assigned this Dec 18, 2024
Copy link
Contributor

github-actions bot commented Dec 18, 2024

npm Snapshot: Published

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

Example:

yarn add @khanacademy/perseus@PR2032

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

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

Copy link
Contributor

github-actions bot commented Dec 18, 2024

Size Change: +741 B (+0.06%)

Total Size: 1.27 MB

Filename Size Change
packages/perseus/dist/es/index.js 418 kB +462 B (+0.11%)
packages/perseus/dist/es/strings.js 5.21 kB +279 B (+5.66%) 🔍
ℹ️ 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 78 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.67 kB
packages/simple-markdown/dist/es/index.js 12.5 kB

compressed-size-action

@anakaren-rojas anakaren-rojas changed the title docs(changeset): adds aria labels to line segment feat(LEMS01733): adds aria labels to line segment Dec 18, 2024
@anakaren-rojas anakaren-rojas changed the title feat(LEMS01733): adds aria labels to line segment feat(LEMS-1733): adds aria labels to line segment Dec 18, 2024
@anakaren-rojas anakaren-rojas marked this pull request as ready for review December 18, 2024 23:34
Copy link
Contributor

@nishasy nishasy left a comment

Choose a reason for hiding this comment

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

A couple of small requests.

packages/perseus/src/strings.ts Outdated Show resolved Hide resolved
packages/perseus/src/strings.ts Outdated Show resolved Hide resolved
srAngleGraphAriaLabel: {
context:
"Screenreader-accessible label for an angle on a coordinate plane.",
message: "An angle on a coordinate plane",
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a period to the end of this?


function getLengthOfSegment(segment: PairOfPoints) {
return kpoint.distanceToPoint(...segment);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit (Optional): Since this component is not using stuff inside the component (everything it needs is passed into the parameters), you can move it outside the component, maybe at the top of this file. That way it won't re-initialize on every render.

This won't really make a difference in performance in this particular case, so it's really up to you, but I believe that's considered good practice.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oops, I meant to write "Since this function is not using stuff inside the component"

aria-label={wholeSegmentAriaLabel}
aria-describedby="segment-description"
>
<>
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 we might still want a label on the overall segments graph saying something like "[Num] segments" so the user knows what to expect before going through each segment individually.

}}
/>
<g
id={`segment-description-${i}`}
Copy link
Contributor

Choose a reason for hiding this comment

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

You still need to use React.useId() to make sure that it's referring to the correct description if there are multiple interactive graphs on the page.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I see, you're talking about having multiple instances of the line segment graph on a single page, right?
I wonder if the ID creation should be bubbled up to the Mafs graph to ensure that we're not getting the same ID in multiple instances for all the graphs, then the individual graphs can consume the IDs.
It looks like we already have a unique ID being generated there, we would just need to consume it

Copy link
Contributor

Choose a reason for hiding this comment

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

You can bubble it down, but I think just adding another React.useId() at the top of the current file is much less work. Then you don't have to bubble it down into everything and keep passing it around everywhere even when not strictly necessary.

I'm not aware of performance issues with React.useId() so I'd personally go with that approach myself, but it's up to you.

Copy link
Contributor

@nishasy nishasy left a comment

Choose a reason for hiding this comment

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

Nice! This is really coming together.

Note: We'll still have to figure out the aria label/description for the middle section (missing from the SRUX doc I think) after the holidays.

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