Skip to content

Commit f5d08b7

Browse files
Adding partially inaccessible functions to InteractiveGraph and LabelImage. (#2553)
## Summary: Adding partially inaccessible functions to InteractiveGraph and LabelImage. These functions detect the state in which these functions are inaccessible. Those states are: InteractiveGraph: - interactive graphs with graphie backgrounds. - interactive graphs with a protractor. LabelImage: - label image widgets with background images that don't have alt text Issue: LEMS-3102 ## Test plan: Run `pnpm test`, all tests should pass Go to storybook page [chromatic]/?path=/story/perseuseditor-editorpage--demo - Add interactive graphs with inaccessible states (listed above) and confirm they are flagged as inaccessible. - Add label image with inaccessible state and confirm it flags as inaccessible. Author: catandthemachines Reviewers: jeremywiebe, tatianasnook, catandthemachines Required Reviewers: Approved By: tatianasnook, jeremywiebe Checks: ✅ 8 checks were successful Pull Request URL: #2553
1 parent ae58c67 commit f5d08b7

File tree

7 files changed

+81
-15
lines changed

7 files changed

+81
-15
lines changed

.changeset/chilly-jokes-teach.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@khanacademy/perseus": minor
3+
"@khanacademy/perseus-core": minor
4+
"@khanacademy/perseus-editor": minor
5+
"@khanacademy/perseus-linter": minor
6+
---
7+
8+
Adding partically accessible widget function to interactive graph and label image.

packages/perseus-core/src/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,11 @@ export {registerCoreWidgets} from "./widgets/core-widget-registry";
191191

192192
export {traverse} from "./traversal";
193193
export {isItemAccessible, violatingWidgets} from "./accessibility";
194+
export {
195+
isLabeledSVG,
196+
getRealImageUrl,
197+
getBaseUrl,
198+
getSvgUrl,
199+
getDataUrl,
200+
getImageSizeModern,
201+
} from "./utils/util.graphie";

packages/perseus-core/src/widgets/interactive-graph/index.ts

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
import {isLabeledSVG} from "../../utils/util.graphie";
2+
13
import getInteractiveGraphPublicWidgetOptions from "./interactive-graph-util";
24

3-
import type {PerseusInteractiveGraphWidgetOptions} from "../../data-schema";
5+
import type {
6+
PerseusInteractiveGraphWidgetOptions,
7+
PerseusWidgetOptions,
8+
} from "../../data-schema";
49
import type {WidgetLogic} from "../logic-export.types";
510

611
export type InteractiveGraphDefaultWidgetOptions = Pick<
@@ -44,8 +49,31 @@ const interactiveGraphWidgetLogic: WidgetLogic = {
4449
name: "interactive-graph",
4550
defaultWidgetOptions,
4651
getPublicWidgetOptions: getInteractiveGraphPublicWidgetOptions,
47-
// TODO(LEMS-3102): add partially inaccessible function
48-
accessible: true,
52+
// Function determining if a interactive graph is accessible.
53+
// Interactive Graphs are accessible as long as:
54+
// 1. They do not contain a protractor
55+
// 2. They do not contain a graphie background image
56+
accessible: (widgetOptions: PerseusWidgetOptions): boolean => {
57+
const interactiveGraphOptions =
58+
widgetOptions as PerseusInteractiveGraphWidgetOptions;
59+
60+
// Return false (inaccessible) if the interactive graph contains
61+
// a protractor.
62+
if (interactiveGraphOptions.showProtractor) {
63+
return false;
64+
}
65+
66+
// Return false (inaccessible) if the interactive graph contains
67+
// a graphie background image.
68+
if (
69+
interactiveGraphOptions.backgroundImage?.url &&
70+
isLabeledSVG(interactiveGraphOptions.backgroundImage?.url)
71+
) {
72+
return false;
73+
}
74+
75+
return true;
76+
},
4977
};
5078

5179
export default interactiveGraphWidgetLogic;

packages/perseus-core/src/widgets/label-image/index.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import getLabelImagePublicWidgetOptions from "./label-image-util";
22

3-
import type {PerseusLabelImageWidgetOptions} from "../../data-schema";
3+
import type {
4+
PerseusLabelImageWidgetOptions,
5+
PerseusWidgetOptions,
6+
} from "../../data-schema";
47
import type {WidgetLogic} from "../logic-export.types";
58

69
export type LabelImageDefaultWidgetOptions = Pick<
@@ -30,8 +33,21 @@ const labelImageWidgetLogic: WidgetLogic = {
3033
name: "label-image",
3134
defaultWidgetOptions,
3235
getPublicWidgetOptions: getLabelImagePublicWidgetOptions,
33-
// TODO(LEMS-3103): add partially inaccessible function
34-
accessible: true,
36+
// Function determining if a label image is accessible.
37+
// Label Images is inaccessible if it does not have alt text for the image.
38+
accessible: (widgetOptions: PerseusWidgetOptions): boolean => {
39+
const labelImageOptions =
40+
widgetOptions as PerseusLabelImageWidgetOptions;
41+
42+
if (
43+
labelImageOptions.imageUrl !== "" &&
44+
labelImageOptions.imageAlt === ""
45+
) {
46+
return false;
47+
}
48+
49+
return true;
50+
},
3551
};
3652

3753
export default labelImageWidgetLogic;

packages/perseus/src/util.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1+
import {
2+
getRealImageUrl,
3+
getBaseUrl,
4+
getSvgUrl,
5+
getDataUrl,
6+
getImageSizeModern,
7+
isLabeledSVG,
8+
} from "@khanacademy/perseus-core";
19
import {KhanAnswerTypes} from "@khanacademy/perseus-score";
210
import _ from "underscore";
311

4-
import * as GraphieUtil from "./util.graphie";
5-
612
import type {Range} from "@khanacademy/perseus-core";
713
import type * as React from "react";
814

@@ -537,7 +543,7 @@ function getImageSize(
537543
}
538544
};
539545

540-
img.src = GraphieUtil.getRealImageUrl(url);
546+
img.src = getRealImageUrl(url);
541547
}
542548

543549
/**
@@ -618,12 +624,12 @@ const Util = {
618624
supportsPassiveEvents,
619625
captureScratchpadTouchStart,
620626
getImageSize,
621-
getImageSizeModern: GraphieUtil.getImageSizeModern,
622-
getRealImageUrl: GraphieUtil.getRealImageUrl,
623-
isLabeledSVG: GraphieUtil.isLabeledSVG,
624-
getBaseUrl: GraphieUtil.getBaseUrl,
625-
getSvgUrl: GraphieUtil.getSvgUrl,
626-
getDataUrl: GraphieUtil.getDataUrl,
627+
getImageSizeModern: getImageSizeModern,
628+
getRealImageUrl: getRealImageUrl,
629+
isLabeledSVG: isLabeledSVG,
630+
getBaseUrl: getBaseUrl,
631+
getSvgUrl: getSvgUrl,
632+
getDataUrl: getDataUrl,
627633
textarea,
628634
unescapeMathMode,
629635
} as const;

0 commit comments

Comments
 (0)