@khanacademy/perseus 1.0.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/dist/es/index.css +17 -8
- package/dist/es/index.js +258 -223
- package/dist/es/index.js.map +1 -1
- package/dist/index.css +17 -8
- package/dist/index.js +261 -225
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/__stories__/input-with-examples.stories.jsx +1 -0
- package/src/components/input-with-examples.jsx +41 -24
- package/src/components/number-input.jsx +2 -2
- package/src/components/simple-keypad-input.jsx +18 -21
- package/src/components/text-input.jsx +5 -3
- package/src/index.js +1 -1
- package/src/multi-items/__tests__/__snapshots__/multi-renderer_test.js.snap +356 -65
- package/src/multi-items/__tests__/multi-renderer_test.js +9 -9
- package/src/perseus-types.js +18 -7
- package/src/styles/perseus-renderer.less +8 -2
- package/src/styles/widgets/matrix.less +2 -0
- package/src/styles/widgets/passage.less +9 -5
- package/src/util/answer-types.js +2 -3
- package/src/util/math.js +3 -10
- package/src/widgets/__stories__/numeric-input.stories.jsx +94 -7
- package/src/widgets/__tests__/__snapshots__/definition_test.js.snap +4 -4
- package/src/widgets/__tests__/__snapshots__/graded-group-set-jipt_test.jsx.snap +15 -6
- package/src/widgets/__tests__/__snapshots__/graded-group-set_test.jsx.snap +5 -2
- package/src/widgets/__tests__/__snapshots__/graded-group_test.jsx.snap +4 -1
- package/src/widgets/__tests__/__snapshots__/group_test.jsx.snap +228 -67
- package/src/widgets/__tests__/__snapshots__/matrix_test.jsx.snap +24 -24
- package/src/widgets/__tests__/__snapshots__/numeric-input_test.jsx.snap +4 -4
- package/src/widgets/__tests__/__snapshots__/radio_test.jsx.snap +2581 -679
- package/src/widgets/__tests__/group_test.jsx +4 -4
- package/src/widgets/__tests__/numeric-input_test.jsx +12 -8
- package/src/widgets/__tests__/passage_test.jsx +81 -0
- package/src/widgets/__tests__/radio/base-radio_test.jsx +55 -7
- package/src/widgets/__tests__/radio/choice_test.jsx +164 -63
- package/src/widgets/__tests__/radio_test.jsx +39 -15
- package/src/widgets/definition.jsx +1 -1
- package/src/widgets/graded-group.jsx +5 -1
- package/src/widgets/group.jsx +84 -102
- package/src/widgets/input-number.jsx +6 -1
- package/src/widgets/matrix.jsx +17 -1
- package/src/widgets/numeric-input.jsx +99 -86
- package/src/widgets/radio/base-radio.jsx +3 -1
- package/src/widgets/radio/choice-a11y-text.js +62 -0
- package/src/widgets/radio/choice-icon/choice-icon.jsx +0 -68
- package/src/widgets/radio/choice-icon/library-choice-icon.jsx +5 -10
- package/src/widgets/radio/choice-icon/sat-choice-icon.jsx +3 -12
- package/src/widgets/radio/choice.jsx +46 -3
|
@@ -18,6 +18,7 @@ import {ApiOptions} from "../../perseus-api.jsx";
|
|
|
18
18
|
import * as styleConstants from "../../styles/constants.js";
|
|
19
19
|
import mediaQueries from "../../styles/media-queries.js";
|
|
20
20
|
|
|
21
|
+
import getA11yText from "./choice-a11y-text.js";
|
|
21
22
|
import ChoiceIcon from "./choice-icon/choice-icon.jsx";
|
|
22
23
|
import OptionStatus from "./option-status.jsx";
|
|
23
24
|
import {getChoiceLetter} from "./util.js";
|
|
@@ -74,6 +75,15 @@ type ChoicePropsWithForwardRef = {|
|
|
|
74
75
|
...WithForwardRef,
|
|
75
76
|
|};
|
|
76
77
|
|
|
78
|
+
// Note(TB): Received errors when using useUniqueIdWithMock
|
|
79
|
+
// so created this workaround function. Will update when
|
|
80
|
+
// useUniqueIdWithMock is available.
|
|
81
|
+
// https://khanacademy.atlassian.net/browse/FEI-4861?atlOrigin=eyJpIjoiNDJlZWMwNjM1NWJhNDBkMWFjY2FmN2I0ZjcxZmQxOGUiLCJwIjoiaiJ9
|
|
82
|
+
let id = 0;
|
|
83
|
+
function uniqueId() {
|
|
84
|
+
return `choice-${id++}`;
|
|
85
|
+
}
|
|
86
|
+
|
|
77
87
|
function Choice(props: ChoicePropsWithForwardRef): React.Node {
|
|
78
88
|
const {
|
|
79
89
|
disabled,
|
|
@@ -153,6 +163,16 @@ function Choice(props: ChoicePropsWithForwardRef): React.Node {
|
|
|
153
163
|
(!apiOptions.satStyling && !reviewMode && apiOptions.readOnly) ||
|
|
154
164
|
crossedOut;
|
|
155
165
|
|
|
166
|
+
const letter = getChoiceLetter(pos);
|
|
167
|
+
const a11yText = getA11yText(
|
|
168
|
+
letter,
|
|
169
|
+
checked,
|
|
170
|
+
correct,
|
|
171
|
+
crossedOut,
|
|
172
|
+
showCorrectness,
|
|
173
|
+
);
|
|
174
|
+
const choiceId = uniqueId();
|
|
175
|
+
|
|
156
176
|
return (
|
|
157
177
|
<div
|
|
158
178
|
style={{
|
|
@@ -168,6 +188,31 @@ function Choice(props: ChoicePropsWithForwardRef): React.Node {
|
|
|
168
188
|
opacity: showDimmed ? 0.5 : 1.0,
|
|
169
189
|
}}
|
|
170
190
|
>
|
|
191
|
+
<div className="perseus-sr-only">
|
|
192
|
+
<input
|
|
193
|
+
type={multipleSelect ? "checkbox" : "radio"}
|
|
194
|
+
id={choiceId}
|
|
195
|
+
checked={checked}
|
|
196
|
+
onClick={() => {
|
|
197
|
+
// If we're checking a crossed-out option, let's
|
|
198
|
+
// also uncross it.
|
|
199
|
+
sendChange({
|
|
200
|
+
checked: !checked,
|
|
201
|
+
crossedOut: false,
|
|
202
|
+
});
|
|
203
|
+
}}
|
|
204
|
+
onChange={() => {}}
|
|
205
|
+
disabled={
|
|
206
|
+
disabled ||
|
|
207
|
+
apiOptions.staticRender ||
|
|
208
|
+
apiOptions.readOnly
|
|
209
|
+
}
|
|
210
|
+
tabIndex={-1}
|
|
211
|
+
/>
|
|
212
|
+
<label htmlFor={choiceId}>
|
|
213
|
+
{a11yText} {content}
|
|
214
|
+
</label>
|
|
215
|
+
</div>
|
|
171
216
|
<Clickable
|
|
172
217
|
onClick={() => {
|
|
173
218
|
// If we're checking a crossed-out option, let's
|
|
@@ -183,11 +228,9 @@ function Choice(props: ChoicePropsWithForwardRef): React.Node {
|
|
|
183
228
|
apiOptions.staticRender ||
|
|
184
229
|
apiOptions.readOnly
|
|
185
230
|
}
|
|
186
|
-
aria-label={`Select Choice ${getChoiceLetter(pos)}`}
|
|
187
|
-
aria-checked={checked ? "true" : "false"}
|
|
188
|
-
role={"checkbox"}
|
|
189
231
|
style={{flex: 1}}
|
|
190
232
|
ref={(forwardedRef: any)}
|
|
233
|
+
aria-hidden="true"
|
|
191
234
|
>
|
|
192
235
|
{({hovered, focused, pressed}) => (
|
|
193
236
|
<div
|