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 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
776c38b
docs(changeset): adds aria labels to line segment
anakaren-rojas Dec 18, 2024
bf27d16
add aria labels to line segment
anakaren-rojas Dec 18, 2024
76391ec
use line segment label
anakaren-rojas Dec 18, 2024
25b8121
Merge branch 'main' into LEMS-1733-add-aria-label-to-line-segment
anakaren-rojas Dec 19, 2024
de68801
remove role from segment
anakaren-rojas Dec 19, 2024
0616ef8
Merge branch 'main' into LEMS-1733-add-aria-label-to-line-segment
anakaren-rojas Dec 19, 2024
08fd6bf
add description for multiple segments
anakaren-rojas Dec 20, 2024
a4f033a
update strings
anakaren-rojas Dec 20, 2024
67b3bd7
add periods at the end of sentences
anakaren-rojas Dec 23, 2024
06114d8
update strings to include multiples and add desc for whole graph
anakaren-rojas Dec 23, 2024
1f6b8b4
move function outside of component
anakaren-rojas Dec 27, 2024
822097d
add unique id to the descriptions
anakaren-rojas Dec 27, 2024
4981fdc
remove unique id from aria described by key
anakaren-rojas Dec 27, 2024
bacaad4
add missing id
anakaren-rojas Dec 27, 2024
717bd34
readd key
anakaren-rojas Dec 27, 2024
42d5288
remove context and message objects
anakaren-rojas Jan 7, 2025
ec9d977
Merge branch 'main' into LEMS-1733-add-aria-label-to-line-segment
anakaren-rojas Jan 7, 2025
072225a
lint fix
anakaren-rojas Jan 7, 2025
1206856
Merge branch 'main' into LEMS-1733-add-aria-label-to-line-segment
anakaren-rojas Jan 8, 2025
d070c09
add placeholder for grab handle aria label
anakaren-rojas Jan 15, 2025
9221928
Merge branch 'main' into LEMS-1733-add-aria-label-to-line-segment
nishasy Jan 21, 2025
2adacae
Remove unused string. Make the description the label.
nishasy Jan 21, 2025
97a9970
Add grab handle string
nishasy Jan 21, 2025
4235cd7
Separate length into description
nishasy Jan 21, 2025
30061d3
Describe interactive elements in outer graph
nishasy Jan 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fuzzy-cheetahs-develop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@khanacademy/perseus": minor
---

adds aria labels to line segment
56 changes: 55 additions & 1 deletion packages/perseus/src/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,29 @@ export type PerseusStrings = {
tsX: string;
tsY: string;
}) => string;
srSegmentGraphAriaLabel: string;
srSegmentGraphAriaDescription: ({
point1X,
point1Y,
point2X,
point2Y,
length,
}: {
point1X: string;
point1Y: string;
point2X: string;
point2Y: string;
length: string;
}) => string;
srSegmentGraphEndpointAriaLabel: ({
endpointNumber,
x,
y,
}: {
endpointNumber: number;
x: string;
y: string;
}) => string;
// The above strings are used for interactive graph SR descriptions.
};

Expand Down Expand Up @@ -543,13 +566,33 @@ export const strings: {
message:
"Point 2, vertex at %(x)s comma %(y)s. Angle %(angleMeasure)s degrees",
},
srAngleGraphAriaLabel: "An angle on a coordinate plane.",
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?

},
srAngleGraphAriaDescription: {
context:
"Screenreader-only description of an angle on a coordinate plane.",
message:
"The angle measure is %(angleMeasure)s degrees with a vertex at %(vertexX)s comma %(vertexY)s, a point on the initial side at %(isX)s comma %(isY)s and a point on the terminal side at %(tsX)s comma %(tsY)s",
},
srSegmentGraphAriaLabel: {
context:
"Screenreader-accessible description of a line segment on a coordinate plane.",
message: "A line segment on a coordinate plane",
},
srSegmentGraphAriaDescription: {
context:
"Screenreader-only description of a line segment on a coordinate plane.",
message:
"Endpoint 1 at %(point1X)s comma %(point1Y)s. Endpoint 2 %(point2X)s comma %(point2Y)s. Segment length %(length)s",
anakaren-rojas marked this conversation as resolved.
Show resolved Hide resolved
},
srSegmentGraphEndpointAriaLabel: {
context:
"Screenreader-accessible label for an endpoint of a line segment on a coordinate plane.",
message: "Endpoint $(endpointNumber)s at $(x)s comma $(y)s",
anakaren-rojas marked this conversation as resolved.
Show resolved Hide resolved
},
// The above strings are used for interactive graph SR descriptions.
};

Expand Down Expand Up @@ -767,5 +810,16 @@ export const mockStrings: PerseusStrings = {
tsY,
}) =>
`The angle measure is ${angleMeasure} degrees with a vertex at ${vertexX} comma ${vertexY}, a point on the initial side at ${isX} comma ${isY} and a point on the terminal side at ${tsX} comma ${tsY}.`,
srSegmentGraphAriaLabel: "A line segment on a coordinate plane.",
srSegmentGraphAriaDescription: ({
point1X,
point1Y,
point2X,
point2Y,
length,
}) =>
`Endpoint 1 at ${point1X} comma ${point1Y}. Endpoint 2 at ${point2X} comma ${point2Y}. Segment length ${length}`,
srSegmentGraphEndpointAriaLabel: ({endpointNumber, x, y}) =>
`Endpoint ${endpointNumber} at ${x} comma ${y}`,
// The above strings are used for interactive graph SR descriptions.
};
53 changes: 48 additions & 5 deletions packages/perseus/src/widgets/interactive-graphs/graphs/segment.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import {point as kpoint} from "@khanacademy/kmath";
import * as React from "react";

import {usePerseusI18n} from "../../../components/i18n-context";
import {X, Y} from "../math";
import {actions} from "../reducer/interactive-graph-action";

import {MovableLine} from "./components/movable-line";
import {srFormatNumber} from "./screenreader-text";

import type {
Dispatch,
Expand All @@ -24,12 +28,36 @@ export function renderSegmentGraph(

type SegmentProps = MafsGraphProps<SegmentGraphState>;

const SegmentGraph = (props: SegmentProps) => {
const {dispatch} = props;
const {coords: segments} = props.graphState;
const SegmentGraph = ({dispatch, graphState}: SegmentProps) => {
const {coords: segments} = graphState;
const {strings, locale} = usePerseusI18n();
const lengthOfSegment =
segments[0] && kpoint.distanceToPoint(...segments[0]);

const wholeSegmentAriaLabel = strings.srSegmentGraphAriaLabel;
const wholeSegmentAriaDescription =
segments[0] &&
strings.srSegmentGraphAriaDescription({
point1X: srFormatNumber(segments[0][0][X], locale),
point1Y: srFormatNumber(segments[0][0][Y], locale),
point2X: srFormatNumber(segments[0][1][X], locale),
point2Y: srFormatNumber(segments[0][1][Y], locale),
length: srFormatNumber(lengthOfSegment, locale),
});
anakaren-rojas marked this conversation as resolved.
Show resolved Hide resolved

function formatSegment(endpointNumber: number, x: number, y: number) {
return strings.srSegmentGraphEndpointAriaLabel({
endpointNumber: endpointNumber,
x: srFormatNumber(x, locale),
y: srFormatNumber(y, locale),
});
}

return (
<>
<g
aria-label={wholeSegmentAriaLabel}
aria-describedby="segment-description"
>
{segments?.map((segment, i) => (
<MovableLine
key={i}
Expand All @@ -49,8 +77,23 @@ const SegmentGraph = (props: SegmentProps) => {
),
);
}}
ariaLabels={{
point1AriaLabel: formatSegment(
1,
segment[0][X],
segment[0][Y],
),
point2AriaLabel: formatSegment(
2,
segment[1][X],
segment[1][Y],
),
}}
/>
))}
</>
<g id="segment-description" style={{display: "hidden"}}>
anakaren-rojas marked this conversation as resolved.
Show resolved Hide resolved
{wholeSegmentAriaDescription}
</g>
</g>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ describe("MafsGraph", () => {
/>,
);

expectLabelInDoc("Point 1 at 0 comma 0");
expectLabelInDoc("Point 2 at -7 comma 0.5");
expectLabelInDoc("Endpoint 1 at 0 comma 0");
expectLabelInDoc("Endpoint 2 at -7 comma 0.5");
});

it("renders ARIA labels for each point (multiple segments)", () => {
Expand Down Expand Up @@ -187,10 +187,10 @@ describe("MafsGraph", () => {
/>,
);

expectLabelInDoc("Point 1 at 0 comma 0");
expectLabelInDoc("Point 2 at -7 comma 0.5");
expectLabelInDoc("Point 1 at 1 comma 1");
expectLabelInDoc("Point 2 at 7 comma 0.5");
expectLabelInDoc("Endpoint 1 at 0 comma 0");
expectLabelInDoc("Endpoint 2 at -7 comma 0.5");
expectLabelInDoc("Endpoint 1 at 1 comma 1");
expectLabelInDoc("Endpoint 2 at 7 comma 0.5");
});

it("renders ARIA labels for each point (linear)", () => {
Expand Down
Loading