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-2662): handle angle aria label updates #1940

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 2, 2024

Summary:

  • Adds SR functionality for angle sides and vertex
  • Adds variations of 6 variations of angle strings - initial side copy (x2), updated side copy (x2), initial vertex copy, updated vertex copy

Issue: LEMS-2662

Test plan:

Testing Steps

  1. Navigate to chromatic
  2. Add an interactive graph widget and update the answer type to Angle
  3. With screen reader on - move any of the points on the graph
  4. Enable Show angle measures and move points
  5. Enable Allow reflex angles and move points

Expected behavior

  1. Screen Reader reads point coordinates (always)
  2. When Show angle measures is not enabled, screen reader does not read out angle measure
  3. When Show angle measures is enabled, angle measure is read out with vertex
  4. When Show angle measures and Allow reflex angles are enabled, Screen Reader reads out reflex angles

Screen Recordings:

Without angle measures

Screen.Recording.2024-12-03.at.14.53.13.mov

With angle measures

Screen.Recording.2024-12-03.at.14.53.53.mov

@anakaren-rojas anakaren-rojas self-assigned this Dec 2, 2024
@anakaren-rojas anakaren-rojas changed the title handle angle aria label updates feat(LEMS-2662): handle angle aria label updates Dec 2, 2024
Copy link
Contributor

github-actions bot commented Dec 3, 2024

npm Snapshot: Published

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

Example:

yarn add @khanacademy/perseus@PR1940

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

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

Copy link
Contributor

github-actions bot commented Dec 3, 2024

Size Change: +799 B (+0.06%)

Total Size: 1.29 MB

Filename Size Change
packages/perseus/dist/es/index.js 426 kB +512 B (+0.12%)
packages/perseus/dist/es/strings.js 3.99 kB +287 B (+7.76%) 🔍
ℹ️ 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 697 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

@anakaren-rojas anakaren-rojas marked this pull request as ready for review December 3, 2024 23:09
@khan-actions-bot khan-actions-bot requested a review from a team December 3, 2024 23:09
@khan-actions-bot
Copy link
Contributor

khan-actions-bot commented Dec 3, 2024

Gerald

Required Reviewers
  • @Khan/perseus for changes to .changeset/famous-rockets-occur.md, packages/perseus/src/strings.ts, packages/perseus/src/widgets/interactive-graphs/mafs-graph.test.tsx, packages/perseus/src/widgets/interactive-graphs/graphs/angle.tsx, packages/perseus/src/widgets/interactive-graphs/math/angles.ts

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

@anakaren-rojas anakaren-rojas requested review from nishasy and catandthemachines and removed request for a team December 3, 2024 23:09
Copy link
Member

@benchristel benchristel left a comment

Choose a reason for hiding this comment

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

This is exciting!

Requesting changes because we're ultimately going to want a different approach to aria-live notifications (see my inline comment about avoiding useState and building for the upcoming Wonder Blocks API) and I'd prefer to start designing for that now.

packages/perseus/src/strings.ts Outdated Show resolved Hide resolved
updateVertexAriaLabel(coords[1]);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [showAngles]);

Copy link
Member

Choose a reason for hiding this comment

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

I think we could avoid using the useState and useEffect hooks here if we:

  • compute aria labels from the graphState prop
  • use aria-live to notify the user of changes to the graph

This would ensure that the SR view and the visible view never get out of sync, since both would be pure functions of graphState. Currently, all the individual graph components are stateless (or nearly so — there are a couple useStates for hover and dragging effects) and I'd like to keep it that way.

Wonder Blocks is planning an API for sending aria-live notifications, but since it's not built yet, I think what we could do is write a minimal implementation of the same API and swap in the WB one when it's ready. I'd be down to pair or consult on that if you want.

Comment on lines 157 to 168
export function getClockwiseCoords(
coords: Vector2[],
vertex: vec.Vector2,
allowReflexAngles: boolean = false,
) {
// Check if the points are clockwise or not, depending on whether we allow reflex angles
const areClockwise = clockwise([...coords, vertex]);
const shouldReverseCoords = areClockwise && !allowReflexAngles;

// Reverse the coordinates accordingly to ensure the angle is calculated correctly
return shouldReverseCoords ? coords : coords.reverse();
}
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for refactoring this code!

It seems like this duplicates some of the logic from getClockwiseAngle in interactive-graphs/math/angles.ts. Could we use that function to calculate the angle measure here? getClockwiseAngle is used for scoring, and it would be nice if we could use the same function to calculate the angle label.

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 yes, you're right, it looks like it combines both the getClockwiseCoords and the getWholeAngleMeasure methods into one! let me test it out

Copy link
Contributor Author

@anakaren-rojas anakaren-rojas Dec 4, 2024

Choose a reason for hiding this comment

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

ok, so I tested this out and using the getClockwiseAngle function introduces a regression in the graph 😢
image
The very small difference between how we determine whether the coordinates should be reversed is the culprit:
In getClockwiseAngle
const shouldReverseCoords = !areClockwise || allowReflexAngles;
In getWholeAngleMeasure
const shouldReverseCoords = areClockwise && !allowReflexAngles;

EDIT:
I realized that using getClockwiseAngle in angles served the original purpose that these two new methods were supposed to serve, so there's no longer a need to pull this logic out of angle-indicators; I'm leaving angle-indicators as-is

Copy link
Member

Choose a reason for hiding this comment

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

I like these tests!

[1, 0],
[0, 0],
]);
});
Copy link
Member

Choose a reason for hiding this comment

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

I'm a bit confused by this. The function is called getClockwiseCoords but it can return counterclockwise coords?

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