diff --git a/.changeset/cyan-dots-compete.md b/.changeset/cyan-dots-compete.md
new file mode 100644
index 0000000000..1e5c8c3406
--- /dev/null
+++ b/.changeset/cyan-dots-compete.md
@@ -0,0 +1,5 @@
+---
+"@khanacademy/perseus": minor
+---
+
+Accessibility and Usability Enhancements for Explanation Widget
diff --git a/config/cypress/support.ts b/config/cypress/support.ts
index 208ebd5b42..cf63c09403 100644
--- a/config/cypress/support.ts
+++ b/config/cypress/support.ts
@@ -2,6 +2,8 @@
import "cypress-jest-adapter";
// eslint-disable-next-line import/no-unassigned-import
import "cypress-wait-until";
+// eslint-disable-next-line import/no-unassigned-import
+import "cypress-real-events";
if (Cypress.env("CYPRESS_COVERAGE")) {
// @ts-expect-error - TS1378 - (trust me!) Top-level 'await' expressions are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', or 'nodenext', and the 'target' option is set to 'es2017' or higher.
diff --git a/config/cypress/tsconfig.json b/config/cypress/tsconfig.json
index 5bd0784678..cf44157e20 100644
--- a/config/cypress/tsconfig.json
+++ b/config/cypress/tsconfig.json
@@ -5,7 +5,7 @@
"esModuleInterop": true,
// be explicit about types included
// to avoid clashing with Jest types
- "types": ["cypress", "node"]
+ "types": ["cypress", "node", "cypress-real-events"]
},
"include": ["**/*.ts", "**/*.tsx"]
}
diff --git a/package.json b/package.json
index 1b9bbf677c..d30a987ebb 100644
--- a/package.json
+++ b/package.json
@@ -70,6 +70,7 @@
"css-loader": "^6.8.1",
"cypress": "^13.6.5",
"cypress-jest-adapter": "^0.1.1",
+ "cypress-real-events": "^1.12.0",
"cypress-wait-until": "^3.0.1",
"eslint": "^8.40.0",
"eslint-config-prettier": "^8.8.0",
diff --git a/packages/perseus/src/styles/perseus-renderer.less b/packages/perseus/src/styles/perseus-renderer.less
index b24c62ba2b..ab57c20624 100644
--- a/packages/perseus/src/styles/perseus-renderer.less
+++ b/packages/perseus/src/styles/perseus-renderer.less
@@ -123,7 +123,7 @@
.perseus-renderer > .paragraph > ul:not(.perseus-widget-radio),
.perseus-renderer > .paragraph > ol {
- margin: -11px 0px 22px 0px; // first-level lists need padding
+ margin: 0px 0px 22px 0px; // first-level lists need padding
}
.paragraph ul:not(.perseus-widget-radio, .indicatorContainer) {
diff --git a/packages/perseus/src/widgets/__stories__/explanation.stories.tsx b/packages/perseus/src/widgets/__stories__/explanation.stories.tsx
index 4a40f740f6..1ec7b3e1c0 100644
--- a/packages/perseus/src/widgets/__stories__/explanation.stories.tsx
+++ b/packages/perseus/src/widgets/__stories__/explanation.stories.tsx
@@ -1,7 +1,11 @@
import * as React from "react";
import {RendererWithDebugUI} from "../../../../../testing/renderer-with-debug-ui";
-import {question1, question2} from "../__testdata__/explanation.testdata";
+import {
+ ipsumExample,
+ question1,
+ question2,
+} from "../__testdata__/explanation.testdata";
export default {
title: "Perseus/Widgets/Explanation",
@@ -16,3 +20,7 @@ export const Question1 = (args: StoryArgs): React.ReactElement => {
export const Question2 = (args: StoryArgs): React.ReactElement => {
return ;
};
+
+export const IpsumExample = (args: StoryArgs): React.ReactElement => {
+ return ;
+};
diff --git a/packages/perseus/src/widgets/__testdata__/explanation.testdata.ts b/packages/perseus/src/widgets/__testdata__/explanation.testdata.ts
index 863c60f925..22f9c318a2 100644
--- a/packages/perseus/src/widgets/__testdata__/explanation.testdata.ts
+++ b/packages/perseus/src/widgets/__testdata__/explanation.testdata.ts
@@ -83,3 +83,45 @@ export const randomExplanationGenerator = (): PerseusRenderer => {
},
};
};
+
+export const ipsumExample: PerseusRenderer = {
+ content: `Unidentified vessel travelling at sub warp speed, bearing 235.7.
+ Fluctuations in energy readings from it, Captain.
+ All transporters off.
+ A strange set-up, but I'd say the graviton generator is depolarized.
+ The dark colourings of the scrapes are the leavings of natural rubber,
+ a type of non-conductive sole used by researchers experimenting with electricity.
+ The molecules must have been partly de-phased by the anyon beam.
+ \n[[\u2603 explanation 1]]\n\nSensors indicate no shuttle or other ships in this sector.
+ According to coordinates, we have travelled 7,000 light years and are located near [the system J-25](#).
+ Tractor beam released, sir. Force field maintaining our hull integrity.
+ Damage report? Sections 27, 28 and 29 on decks four, five and six destroyed.
+ `,
+ images: {},
+ widgets: {
+ "explanation 1": {
+ graded: true,
+ version: {
+ major: 0,
+ minor: 0,
+ },
+ static: false,
+ type: "explanation",
+ options: {
+ hidePrompt: "Hide",
+ widgets: {},
+ explanation: `It indicates a [synchronic distortion](#) in the areas emanating triolic waves.
+ The cerebellum, the cerebral cortex, the brain stem,
+ the entire nervous system has been depleted of electrochemical energy.
+ Any device like that would produce high levels of triolic waves.
+ These walls have undergone some kind of [selective molecular polarization](#).
+ I haven't determined if our phaser energy can generate a stable field.
+ We could alter the photons with phase discriminators.
+ `,
+ static: false,
+ showPrompt: "Explanation",
+ },
+ alignment: "default",
+ },
+ },
+};
diff --git a/packages/perseus/src/widgets/__testdata__/graded-group.testdata.ts b/packages/perseus/src/widgets/__testdata__/graded-group.testdata.ts
index 500aa0d15e..8a1350ba23 100644
--- a/packages/perseus/src/widgets/__testdata__/graded-group.testdata.ts
+++ b/packages/perseus/src/widgets/__testdata__/graded-group.testdata.ts
@@ -12,7 +12,7 @@ export const question1: PerseusRenderer = {
options: {
title: "Metabolic strategies of bacteria",
content:
- "1. **Which of the following statements about metabolic strategies of bacteria are true?**\n\n [[☃ categorizer 1]]\n\n [[☃ explanation 1]]",
+ "1. **Which of the following statements about metabolic strategies of bacteria are true?**\n\n [[☃ categorizer 1]]",
images: {},
widgets: {
"categorizer 1": {
@@ -34,40 +34,31 @@ export const question1: PerseusRenderer = {
},
version: {major: 0, minor: 0},
},
- "explanation 1": {
- type: "explanation",
- alignment: "default",
- static: false,
- graded: true,
- options: {
- static: false,
- showPrompt: "Hint",
- hidePrompt: "Hide hint",
- explanation:
- "Some bacteria synthesize their own fuel molecules/fix their own carbon (autotrophic), while others take in fixed carbon from their environments (heterotrophic).\n\nSome autotrophs use light energy to synthesize their own fuel molecules, while others extract energy from chemical sources.\n\nBacteria that extract energy from chemical sources and use it to fix carbon are called chemosynthetic organisms. These bacteria may be essential to communities where light is not available, like those around deep-sea vents. They can form the base of the food chain (act as primary producers) in these ecosystems.\n\nSome bacteria have symbiotic (mutually beneficial) relationships with other organisms, living inside these organisms and providing them with nutrients.\n\n**The following statements about the metabolic strategies of bacteria are true:**\n\n[[☃ categorizer 1]]",
- widgets: {
- "categorizer 1": {
- type: "categorizer",
- alignment: "default",
- static: true,
- graded: true,
- options: {
- static: false,
- items: [
- " Some bacteria conduct photosynthesis and produce oxygen, much like plants.",
- "Bacteria are always autotrophic but they may get energy from either light or chemical sources.",
- "Some chemosynthetic bacteria introduce energy and fixed carbon into communities where photosynthesis is not possible (e.g., deep-sea vents).",
- "Some bacteria live symbiotically inside of host organisms and provide the host with nutrients.",
- ],
- categories: ["True", "False"],
- values: [0, 1, 0, 0],
- randomizeItems: false,
- },
- version: {major: 0, minor: 0},
- },
+ },
+ hint: {
+ content:
+ "Some bacteria synthesize their own fuel molecules/fix their own carbon (autotrophic), while others take in fixed carbon from their environments (heterotrophic).\n\nSome autotrophs use light energy to synthesize their own fuel molecules, while others extract energy from chemical sources.\n\nBacteria that extract energy from chemical sources and use it to fix carbon are called chemosynthetic organisms. These bacteria may be essential to communities where light is not available, like those around deep-sea vents. They can form the base of the food chain (act as primary producers) in these ecosystems.\n\nSome bacteria have symbiotic (mutually beneficial) relationships with other organisms, living inside these organisms and providing them with nutrients.\n\n**The following statements about the metabolic strategies of bacteria are true:**\n\n[[☃ categorizer 1]]",
+ images: {},
+ widgets: {
+ "categorizer 1": {
+ type: "categorizer",
+ alignment: "default",
+ static: true,
+ graded: true,
+ options: {
+ static: false,
+ items: [
+ " Some bacteria conduct photosynthesis and produce oxygen, much like plants.",
+ "Bacteria are always autotrophic but they may get energy from either light or chemical sources.",
+ "Some chemosynthetic bacteria introduce energy and fixed carbon into communities where photosynthesis is not possible (e.g., deep-sea vents).",
+ "Some bacteria live symbiotically inside of host organisms and provide the host with nutrients.",
+ ],
+ categories: ["True", "False"],
+ values: [0, 1, 0, 0],
+ randomizeItems: false,
},
+ version: {major: 0, minor: 0},
},
- version: {major: 0, minor: 0},
},
},
},
diff --git a/packages/perseus/src/widgets/__tests__/__snapshots__/explanation.test.ts.snap b/packages/perseus/src/widgets/__tests__/__snapshots__/explanation.test.ts.snap
index 64ac085a81..cdd38ad52c 100644
--- a/packages/perseus/src/widgets/__tests__/__snapshots__/explanation.test.ts.snap
+++ b/packages/perseus/src/widgets/__tests__/__snapshots__/explanation.test.ts.snap
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
-exports[`Explanation should snapshot for article when expanded: expanded 1`] = `
+exports[`Explanation should snapshot when expanded: expanded 1`] = `
-
-
+ Hide explanation!
+
-
-
-
- This is an explanation
-
-
-
+
-
-
-
-Did you get that?
-
-
-
-
-`;
-
-exports[`Explanation should snapshot for article+mobile when expanded: expanded 1`] = `
-