@khanacademy/wonder-blocks-form 4.9.2 → 4.9.3

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.
Files changed (35) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/components/checkbox-core.d.ts +2 -2
  3. package/dist/components/checkbox.d.ts +2 -2
  4. package/dist/components/choice-internal.d.ts +2 -2
  5. package/dist/components/choice.d.ts +2 -2
  6. package/dist/components/radio-core.d.ts +2 -2
  7. package/dist/components/radio.d.ts +2 -2
  8. package/dist/components/text-area.d.ts +2 -2
  9. package/package.json +7 -7
  10. package/src/__tests__/__snapshots__/custom-snapshot.test.tsx.snap +0 -247
  11. package/src/__tests__/custom-snapshot.test.tsx +0 -48
  12. package/src/components/__tests__/checkbox-group.test.tsx +0 -162
  13. package/src/components/__tests__/checkbox.test.tsx +0 -138
  14. package/src/components/__tests__/field-heading.test.tsx +0 -225
  15. package/src/components/__tests__/labeled-text-field.test.tsx +0 -750
  16. package/src/components/__tests__/radio-group.test.tsx +0 -182
  17. package/src/components/__tests__/text-area.test.tsx +0 -1286
  18. package/src/components/__tests__/text-field.test.tsx +0 -562
  19. package/src/components/checkbox-core.tsx +0 -239
  20. package/src/components/checkbox-group.tsx +0 -174
  21. package/src/components/checkbox.tsx +0 -99
  22. package/src/components/choice-internal.tsx +0 -184
  23. package/src/components/choice.tsx +0 -157
  24. package/src/components/field-heading.tsx +0 -169
  25. package/src/components/group-styles.ts +0 -33
  26. package/src/components/labeled-text-field.tsx +0 -317
  27. package/src/components/radio-core.tsx +0 -171
  28. package/src/components/radio-group.tsx +0 -159
  29. package/src/components/radio.tsx +0 -82
  30. package/src/components/text-area.tsx +0 -430
  31. package/src/components/text-field.tsx +0 -399
  32. package/src/index.ts +0 -17
  33. package/src/util/types.ts +0 -85
  34. package/tsconfig-build.json +0 -19
  35. package/tsconfig-build.tsbuildinfo +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @khanacademy/wonder-blocks-form
2
2
 
3
+ ## 4.9.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 02a1b298: Make sure we don't package tsconfig and tsbuildinfo files
8
+ - Updated dependencies [02a1b298]
9
+ - @khanacademy/wonder-blocks-clickable@4.2.8
10
+ - @khanacademy/wonder-blocks-core@7.0.1
11
+ - @khanacademy/wonder-blocks-icon@4.1.5
12
+ - @khanacademy/wonder-blocks-layout@2.2.1
13
+ - @khanacademy/wonder-blocks-tokens@2.0.1
14
+ - @khanacademy/wonder-blocks-typography@2.1.16
15
+
3
16
  ## 4.9.2
4
17
 
5
18
  ### Patch Changes
@@ -3,8 +3,8 @@ import type { Checked } from "../util/types";
3
3
  /**
4
4
  * The internal stateless ☑️ Checkbox
5
5
  */
6
- declare const CheckboxCore: React.ForwardRefExoticComponent<Readonly<import("../../../wonder-blocks-core/src/util/aria-types").AriaAttributes> & Readonly<{
7
- role?: import("../../../wonder-blocks-core/src/util/aria-types").AriaRole | undefined;
6
+ declare const CheckboxCore: React.ForwardRefExoticComponent<Readonly<import("@khanacademy/wonder-blocks-core").AriaAttributes> & Readonly<{
7
+ role?: import("@khanacademy/wonder-blocks-core").AriaRole | undefined;
8
8
  }> & {
9
9
  checked: Checked;
10
10
  disabled: boolean;
@@ -22,8 +22,8 @@ import type { Checked } from "../util/types";
22
22
  * <Checkbox checked={checked} onChange={setChecked} />
23
23
  * ```
24
24
  */
25
- declare const Checkbox: React.ForwardRefExoticComponent<Readonly<import("../../../wonder-blocks-core/src/util/aria-types").AriaAttributes> & Readonly<{
26
- role?: import("../../../wonder-blocks-core/src/util/aria-types").AriaRole | undefined;
25
+ declare const Checkbox: React.ForwardRefExoticComponent<Readonly<import("@khanacademy/wonder-blocks-core").AriaAttributes> & Readonly<{
26
+ role?: import("@khanacademy/wonder-blocks-core").AriaRole | undefined;
27
27
  }> & {
28
28
  /**
29
29
  * Whether this component is checked or indeterminate
@@ -7,8 +7,8 @@ import type { StyleType } from "@khanacademy/wonder-blocks-core";
7
7
  * and RadioGroup. This design allows for more explicit prop typing. For
8
8
  * example, we can make onChange a required prop on Checkbox but not on Choice
9
9
  * (because for Choice, that prop would be auto-populated by CheckboxGroup).
10
- */ declare const ChoiceInternal: React.ForwardRefExoticComponent<Readonly<import("../../../wonder-blocks-core/src/util/aria-types").AriaAttributes> & Readonly<{
11
- role?: import("../../../wonder-blocks-core/src/util/aria-types").AriaRole | undefined;
10
+ */ declare const ChoiceInternal: React.ForwardRefExoticComponent<Readonly<import("@khanacademy/wonder-blocks-core").AriaAttributes> & Readonly<{
11
+ role?: import("@khanacademy/wonder-blocks-core").AriaRole | undefined;
12
12
  }> & {
13
13
  /** Whether this choice is checked. */
14
14
  checked: boolean | null | undefined;
@@ -66,8 +66,8 @@ import type { StyleType } from "@khanacademy/wonder-blocks-core";
66
66
  * </RadioGroup>
67
67
  * ```
68
68
  */
69
- declare const Choice: React.ForwardRefExoticComponent<Readonly<import("../../../wonder-blocks-core/src/util/aria-types").AriaAttributes> & Readonly<{
70
- role?: import("../../../wonder-blocks-core/src/util/aria-types").AriaRole | undefined;
69
+ declare const Choice: React.ForwardRefExoticComponent<Readonly<import("@khanacademy/wonder-blocks-core").AriaAttributes> & Readonly<{
70
+ role?: import("@khanacademy/wonder-blocks-core").AriaRole | undefined;
71
71
  }> & {
72
72
  /** User-defined. Label for the field. */
73
73
  label: React.ReactNode;
@@ -2,8 +2,8 @@ import * as React from "react";
2
2
  import type { Checked } from "../util/types";
3
3
  /**
4
4
  * The internal stateless 🔘 Radio button
5
- */ declare const RadioCore: React.ForwardRefExoticComponent<Readonly<import("../../../wonder-blocks-core/src/util/aria-types").AriaAttributes> & Readonly<{
6
- role?: import("../../../wonder-blocks-core/src/util/aria-types").AriaRole | undefined;
5
+ */ declare const RadioCore: React.ForwardRefExoticComponent<Readonly<import("@khanacademy/wonder-blocks-core").AriaAttributes> & Readonly<{
6
+ role?: import("@khanacademy/wonder-blocks-core").AriaRole | undefined;
7
7
  }> & {
8
8
  checked: Checked;
9
9
  disabled: boolean;
@@ -6,8 +6,8 @@ import type { StyleType } from "@khanacademy/wonder-blocks-core";
6
6
  *
7
7
  * This component should not really be used by itself because radio buttons are
8
8
  * often grouped together. See RadioGroup.
9
- */ declare const Radio: React.ForwardRefExoticComponent<Readonly<import("../../../wonder-blocks-core/src/util/aria-types").AriaAttributes> & Readonly<{
10
- role?: import("../../../wonder-blocks-core/src/util/aria-types").AriaRole | undefined;
9
+ */ declare const Radio: React.ForwardRefExoticComponent<Readonly<import("@khanacademy/wonder-blocks-core").AriaAttributes> & Readonly<{
10
+ role?: import("@khanacademy/wonder-blocks-core").AriaRole | undefined;
11
11
  }> & {
12
12
  /**
13
13
  * Whether this component is checked
@@ -1,7 +1,7 @@
1
1
  import * as React from "react";
2
2
  import { StyleType } from "@khanacademy/wonder-blocks-core";
3
- declare const TextArea: React.ForwardRefExoticComponent<Readonly<import("../../../wonder-blocks-core/src/util/aria-types").AriaAttributes> & Readonly<{
4
- role?: import("../../../wonder-blocks-core/src/util/aria-types").AriaRole | undefined;
3
+ declare const TextArea: React.ForwardRefExoticComponent<Readonly<import("@khanacademy/wonder-blocks-core").AriaAttributes> & Readonly<{
4
+ role?: import("@khanacademy/wonder-blocks-core").AriaRole | undefined;
5
5
  }> & {
6
6
  /**
7
7
  * The text area value.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khanacademy/wonder-blocks-form",
3
- "version": "4.9.2",
3
+ "version": "4.9.3",
4
4
  "design": "v1",
5
5
  "description": "Form components for Wonder Blocks.",
6
6
  "main": "dist/index.js",
@@ -16,12 +16,12 @@
16
16
  },
17
17
  "dependencies": {
18
18
  "@babel/runtime": "^7.18.6",
19
- "@khanacademy/wonder-blocks-clickable": "^4.2.7",
20
- "@khanacademy/wonder-blocks-core": "^7.0.0",
21
- "@khanacademy/wonder-blocks-icon": "^4.1.4",
22
- "@khanacademy/wonder-blocks-layout": "^2.2.0",
23
- "@khanacademy/wonder-blocks-tokens": "^2.0.0",
24
- "@khanacademy/wonder-blocks-typography": "^2.1.15"
19
+ "@khanacademy/wonder-blocks-clickable": "^4.2.8",
20
+ "@khanacademy/wonder-blocks-core": "^7.0.1",
21
+ "@khanacademy/wonder-blocks-icon": "^4.1.5",
22
+ "@khanacademy/wonder-blocks-layout": "^2.2.1",
23
+ "@khanacademy/wonder-blocks-tokens": "^2.0.1",
24
+ "@khanacademy/wonder-blocks-typography": "^2.1.16"
25
25
  },
26
26
  "peerDependencies": {
27
27
  "aphrodite": "^1.2.5",
@@ -1,247 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`CheckboxCore type:default checked:false 1`] = `
4
- <div>
5
- <input
6
- aria-checked="false"
7
- aria-invalid="false"
8
- class=""
9
- style="appearance: none; height: 16px; width: 16px; min-height: 16px; min-width: 16px; margin: 0px; outline: none; box-sizing: border-box; border-style: solid; border-width: 1px; border-radius: 3px; background-color: rgb(255, 255, 255); border-color: rgba(33,36,44,0.50);"
10
- type="checkbox"
11
- />
12
- </div>
13
- `;
14
-
15
- exports[`CheckboxCore type:default checked:null 1`] = `
16
- <div>
17
- <input
18
- aria-checked="mixed"
19
- aria-invalid="false"
20
- class=""
21
- style="appearance: none; height: 16px; width: 16px; min-height: 16px; min-width: 16px; margin: 0px; outline: none; box-sizing: border-box; border-style: solid; border-width: 0px; border-radius: 3px; background-color: rgb(24, 101, 242);"
22
- type="checkbox"
23
- />
24
- <span
25
- class=""
26
- style="display: inline-block; vertical-align: text-bottom; flex-shrink: 0; flex-grow: 0; mask-size: 100%; mask-repeat: no-repeat; mask-position: center; background-color: rgb(255, 255, 255); width: 12px; height: 12px; mask-image: url(minus-bold.svg); position: absolute; pointer-events: none; margin: 2px;"
27
- />
28
- </div>
29
- `;
30
-
31
- exports[`CheckboxCore type:default checked:true 1`] = `
32
- <div>
33
- <input
34
- aria-checked="true"
35
- aria-invalid="false"
36
- checked=""
37
- class=""
38
- style="appearance: none; height: 16px; width: 16px; min-height: 16px; min-width: 16px; margin: 0px; outline: none; box-sizing: border-box; border-style: solid; border-width: 0px; border-radius: 3px; background-color: rgb(24, 101, 242);"
39
- type="checkbox"
40
- />
41
- <span
42
- class=""
43
- style="display: inline-block; vertical-align: text-bottom; flex-shrink: 0; flex-grow: 0; mask-size: 100%; mask-repeat: no-repeat; mask-position: center; background-color: rgb(255, 255, 255); width: 12px; height: 12px; mask-image: url(check-bold.svg); position: absolute; pointer-events: none; margin: 2px;"
44
- />
45
- </div>
46
- `;
47
-
48
- exports[`CheckboxCore type:disabled checked:false 1`] = `
49
- <div>
50
- <input
51
- aria-checked="false"
52
- aria-invalid="false"
53
- class=""
54
- disabled=""
55
- style="appearance: none; height: 16px; width: 16px; min-height: 16px; min-width: 16px; margin: 0px; outline: none; box-sizing: border-box; border-style: solid; border-width: 1px; border-radius: 3px; cursor: auto; background-color: rgb(247, 248, 250); border-color: rgba(33,36,44,0.16);"
56
- type="checkbox"
57
- />
58
- </div>
59
- `;
60
-
61
- exports[`CheckboxCore type:disabled checked:null 1`] = `
62
- <div>
63
- <input
64
- aria-checked="mixed"
65
- aria-invalid="false"
66
- class=""
67
- disabled=""
68
- style="appearance: none; height: 16px; width: 16px; min-height: 16px; min-width: 16px; margin: 0px; outline: none; box-sizing: border-box; border-style: solid; border-width: 1px; border-radius: 3px; cursor: auto; background-color: rgb(247, 248, 250); border-color: rgba(33,36,44,0.16);"
69
- type="checkbox"
70
- />
71
- <span
72
- class=""
73
- style="display: inline-block; vertical-align: text-bottom; flex-shrink: 0; flex-grow: 0; mask-size: 100%; mask-repeat: no-repeat; mask-position: center; background-color: rgba(33, 36, 44, 0.32); width: 12px; height: 12px; mask-image: url(minus-bold.svg); position: absolute; pointer-events: none; margin: 2px;"
74
- />
75
- </div>
76
- `;
77
-
78
- exports[`CheckboxCore type:disabled checked:true 1`] = `
79
- <div>
80
- <input
81
- aria-checked="true"
82
- aria-invalid="false"
83
- checked=""
84
- class=""
85
- disabled=""
86
- style="appearance: none; height: 16px; width: 16px; min-height: 16px; min-width: 16px; margin: 0px; outline: none; box-sizing: border-box; border-style: solid; border-width: 1px; border-radius: 3px; cursor: auto; background-color: rgb(247, 248, 250); border-color: rgba(33,36,44,0.16);"
87
- type="checkbox"
88
- />
89
- <span
90
- class=""
91
- style="display: inline-block; vertical-align: text-bottom; flex-shrink: 0; flex-grow: 0; mask-size: 100%; mask-repeat: no-repeat; mask-position: center; background-color: rgba(33, 36, 44, 0.32); width: 12px; height: 12px; mask-image: url(check-bold.svg); position: absolute; pointer-events: none; margin: 2px;"
92
- />
93
- </div>
94
- `;
95
-
96
- exports[`CheckboxCore type:error checked:false 1`] = `
97
- <div>
98
- <input
99
- aria-checked="false"
100
- aria-invalid="true"
101
- class=""
102
- style="appearance: none; height: 16px; width: 16px; min-height: 16px; min-width: 16px; margin: 0px; outline: none; box-sizing: border-box; border-style: solid; border-width: 1px; border-radius: 3px; background-color: rgb(252, 238, 236); border-color: #d92916;"
103
- type="checkbox"
104
- />
105
- </div>
106
- `;
107
-
108
- exports[`CheckboxCore type:error checked:null 1`] = `
109
- <div>
110
- <input
111
- aria-checked="mixed"
112
- aria-invalid="true"
113
- class=""
114
- style="appearance: none; height: 16px; width: 16px; min-height: 16px; min-width: 16px; margin: 0px; outline: none; box-sizing: border-box; border-style: solid; border-width: 0px; border-radius: 3px; background-color: rgb(217, 41, 22);"
115
- type="checkbox"
116
- />
117
- <span
118
- class=""
119
- style="display: inline-block; vertical-align: text-bottom; flex-shrink: 0; flex-grow: 0; mask-size: 100%; mask-repeat: no-repeat; mask-position: center; background-color: rgb(255, 255, 255); width: 12px; height: 12px; mask-image: url(minus-bold.svg); position: absolute; pointer-events: none; margin: 2px;"
120
- />
121
- </div>
122
- `;
123
-
124
- exports[`CheckboxCore type:error checked:true 1`] = `
125
- <div>
126
- <input
127
- aria-checked="true"
128
- aria-invalid="true"
129
- checked=""
130
- class=""
131
- style="appearance: none; height: 16px; width: 16px; min-height: 16px; min-width: 16px; margin: 0px; outline: none; box-sizing: border-box; border-style: solid; border-width: 0px; border-radius: 3px; background-color: rgb(217, 41, 22);"
132
- type="checkbox"
133
- />
134
- <span
135
- class=""
136
- style="display: inline-block; vertical-align: text-bottom; flex-shrink: 0; flex-grow: 0; mask-size: 100%; mask-repeat: no-repeat; mask-position: center; background-color: rgb(255, 255, 255); width: 12px; height: 12px; mask-image: url(check-bold.svg); position: absolute; pointer-events: none; margin: 2px;"
137
- />
138
- </div>
139
- `;
140
-
141
- exports[`RadioCore type:default checked:false 1`] = `
142
- <div>
143
- <input
144
- aria-invalid="false"
145
- class=""
146
- style="appearance: none; height: 16px; width: 16px; min-height: 16px; min-width: 16px; margin: 0px; outline: none; box-sizing: border-box; border-style: solid; border-width: 1px; border-radius: 50%; background-color: rgb(255, 255, 255); border-color: rgba(33,36,44,0.50);"
147
- type="radio"
148
- />
149
- </div>
150
- `;
151
-
152
- exports[`RadioCore type:default checked:null 1`] = `
153
- <div>
154
- <input
155
- aria-invalid="false"
156
- class=""
157
- style="appearance: none; height: 16px; width: 16px; min-height: 16px; min-width: 16px; margin: 0px; outline: none; box-sizing: border-box; border-style: solid; border-width: 1px; border-radius: 50%; background-color: rgb(255, 255, 255); border-color: rgba(33,36,44,0.50);"
158
- type="radio"
159
- />
160
- </div>
161
- `;
162
-
163
- exports[`RadioCore type:default checked:true 1`] = `
164
- <div>
165
- <input
166
- aria-invalid="false"
167
- checked=""
168
- class=""
169
- style="appearance: none; height: 16px; width: 16px; min-height: 16px; min-width: 16px; margin: 0px; outline: none; box-sizing: border-box; border-style: solid; border-width: 4px; border-radius: 50%; background-color: rgb(255, 255, 255); border-color: #1865f2;"
170
- type="radio"
171
- />
172
- </div>
173
- `;
174
-
175
- exports[`RadioCore type:disabled checked:false 1`] = `
176
- <div>
177
- <input
178
- aria-invalid="false"
179
- class=""
180
- disabled=""
181
- style="appearance: none; height: 16px; width: 16px; min-height: 16px; min-width: 16px; margin: 0px; outline: none; box-sizing: border-box; border-style: solid; border-width: 1px; border-radius: 50%; cursor: auto; background-color: rgb(247, 248, 250); border-color: rgba(33,36,44,0.16);"
182
- type="radio"
183
- />
184
- </div>
185
- `;
186
-
187
- exports[`RadioCore type:disabled checked:null 1`] = `
188
- <div>
189
- <input
190
- aria-invalid="false"
191
- class=""
192
- disabled=""
193
- style="appearance: none; height: 16px; width: 16px; min-height: 16px; min-width: 16px; margin: 0px; outline: none; box-sizing: border-box; border-style: solid; border-width: 1px; border-radius: 50%; cursor: auto; background-color: rgb(247, 248, 250); border-color: rgba(33,36,44,0.16);"
194
- type="radio"
195
- />
196
- </div>
197
- `;
198
-
199
- exports[`RadioCore type:disabled checked:true 1`] = `
200
- <div>
201
- <input
202
- aria-invalid="false"
203
- checked=""
204
- class=""
205
- disabled=""
206
- style="appearance: none; height: 16px; width: 16px; min-height: 16px; min-width: 16px; margin: 0px; outline: none; box-sizing: border-box; border-style: solid; border-width: 1px; border-radius: 50%; cursor: auto; background-color: rgb(247, 248, 250); border-color: rgba(33,36,44,0.16);"
207
- type="radio"
208
- />
209
- <span
210
- style="position: absolute; top: 4px; left: 4px; height: 8px; width: 8px; border-radius: 50%; background-color: rgba(33, 36, 44, 0.32);"
211
- />
212
- </div>
213
- `;
214
-
215
- exports[`RadioCore type:error checked:false 1`] = `
216
- <div>
217
- <input
218
- aria-invalid="true"
219
- class=""
220
- style="appearance: none; height: 16px; width: 16px; min-height: 16px; min-width: 16px; margin: 0px; outline: none; box-sizing: border-box; border-style: solid; border-width: 1px; border-radius: 50%; background-color: rgb(252, 238, 236); border-color: #d92916;"
221
- type="radio"
222
- />
223
- </div>
224
- `;
225
-
226
- exports[`RadioCore type:error checked:null 1`] = `
227
- <div>
228
- <input
229
- aria-invalid="true"
230
- class=""
231
- style="appearance: none; height: 16px; width: 16px; min-height: 16px; min-width: 16px; margin: 0px; outline: none; box-sizing: border-box; border-style: solid; border-width: 1px; border-radius: 50%; background-color: rgb(252, 238, 236); border-color: #d92916;"
232
- type="radio"
233
- />
234
- </div>
235
- `;
236
-
237
- exports[`RadioCore type:error checked:true 1`] = `
238
- <div>
239
- <input
240
- aria-invalid="true"
241
- checked=""
242
- class=""
243
- style="appearance: none; height: 16px; width: 16px; min-height: 16px; min-width: 16px; margin: 0px; outline: none; box-sizing: border-box; border-style: solid; border-width: 4px; border-radius: 50%; background-color: rgb(255, 255, 255); border-color: #d92916;"
244
- type="radio"
245
- />
246
- </div>
247
- `;
@@ -1,48 +0,0 @@
1
- import * as React from "react";
2
- import {render} from "@testing-library/react";
3
-
4
- import CheckboxCore from "../components/checkbox-core";
5
- import RadioCore from "../components/radio-core";
6
-
7
- const states = ["default", "error", "disabled"];
8
- const checkedStates = [false, true, null];
9
-
10
- describe("CheckboxCore", () => {
11
- states.forEach((state: any) => {
12
- checkedStates.forEach((checked: any) => {
13
- test(`type:${state} checked:${String(checked)}`, () => {
14
- const disabled = state === "disabled";
15
- const {container} = render(
16
- <CheckboxCore
17
- checked={checked}
18
- disabled={disabled}
19
- error={state === "error"}
20
- onClick={() => {}}
21
- />,
22
- );
23
-
24
- expect(container).toMatchSnapshot();
25
- });
26
- });
27
- });
28
- });
29
-
30
- describe("RadioCore", () => {
31
- states.forEach((state: any) => {
32
- checkedStates.forEach((checked: any) => {
33
- test(`type:${state} checked:${String(checked)}`, () => {
34
- const disabled = state === "disabled";
35
- const {container} = render(
36
- <RadioCore
37
- checked={checked}
38
- disabled={disabled}
39
- error={state === "error"}
40
- onClick={() => {}}
41
- />,
42
- );
43
-
44
- expect(container).toMatchSnapshot();
45
- });
46
- });
47
- });
48
- });
@@ -1,162 +0,0 @@
1
- import * as React from "react";
2
- import {render, screen} from "@testing-library/react";
3
- import {userEvent} from "@testing-library/user-event";
4
-
5
- import CheckboxGroup from "../checkbox-group";
6
- import Choice from "../choice";
7
-
8
- describe("CheckboxGroup", () => {
9
- describe("behavior", () => {
10
- const TestComponent = ({errorMessage}: {errorMessage?: string}) => {
11
- const [selectedValues, setSelectedValue] = React.useState([
12
- "a",
13
- "b",
14
- ]);
15
- const handleChange = (selectedValues: any) => {
16
- setSelectedValue(selectedValues);
17
- };
18
- return (
19
- <CheckboxGroup
20
- label="Test"
21
- description="test description"
22
- groupName="test"
23
- onChange={handleChange}
24
- selectedValues={selectedValues}
25
- errorMessage={errorMessage}
26
- >
27
- <Choice label="a" value="a" aria-labelledby="test-a" />
28
- <Choice label="b" value="b" aria-labelledby="test-b" />
29
- <Choice label="c" value="c" aria-labelledby="test-c" />
30
- </CheckboxGroup>
31
- );
32
- };
33
-
34
- it("has the correct items checked", async () => {
35
- // Arrange, Act
36
- render(<TestComponent />);
37
-
38
- const checkboxes = screen.getAllByRole("checkbox");
39
-
40
- // Assert
41
- // a starts off checked
42
- expect(checkboxes[0]).toBeChecked();
43
- expect(checkboxes[1]).toBeChecked();
44
- expect(checkboxes[2]).not.toBeChecked();
45
- });
46
-
47
- it("clicking a selected choice deselects it", async () => {
48
- // Arrange
49
- render(<TestComponent />);
50
-
51
- const checkboxes = screen.getAllByRole("checkbox");
52
-
53
- // Act
54
- await userEvent.click(checkboxes[0]);
55
-
56
- // Assert
57
- expect(checkboxes[0]).not.toBeChecked();
58
- expect(checkboxes[1]).toBeChecked();
59
- expect(checkboxes[2]).not.toBeChecked();
60
- });
61
-
62
- it("should set aria-invalid on choices when there's an error message", async () => {
63
- // Arrange, Act
64
- render(<TestComponent errorMessage="there's an error" />);
65
-
66
- const checkboxes = screen.getAllByRole("checkbox");
67
-
68
- // Assert
69
- expect(checkboxes[0]).toHaveAttribute("aria-invalid", "true");
70
- expect(checkboxes[1]).toHaveAttribute("aria-invalid", "true");
71
- expect(checkboxes[2]).toHaveAttribute("aria-invalid", "true");
72
- });
73
-
74
- it("checks that aria attributes have been added correctly", async () => {
75
- // Arrange, Act
76
- render(<TestComponent />);
77
-
78
- const checkboxes = screen.getAllByRole("checkbox");
79
-
80
- // Assert
81
- expect(checkboxes[0]).toHaveAttribute("aria-labelledby", "test-a");
82
- expect(checkboxes[1]).toHaveAttribute("aria-labelledby", "test-b");
83
- expect(checkboxes[2]).toHaveAttribute("aria-labelledby", "test-c");
84
- });
85
- });
86
-
87
- describe("flexible props", () => {
88
- it("should render with a React.Node label", async () => {
89
- // Arrange, Act
90
- render(
91
- <CheckboxGroup
92
- label={
93
- <span>
94
- label with <strong>strong</strong> text
95
- </span>
96
- }
97
- groupName="test"
98
- onChange={() => {}}
99
- selectedValues={[]}
100
- >
101
- <Choice label="a" value="a" aria-labelledby="test-a" />
102
- <Choice label="b" value="b" aria-labelledby="test-b" />
103
- <Choice label="c" value="c" aria-labelledby="test-c" />
104
- </CheckboxGroup>,
105
- );
106
-
107
- // Assert
108
- expect(await screen.findByText("strong")).toBeInTheDocument();
109
- });
110
-
111
- it("should render with a React.Node description", async () => {
112
- // Arrange, Act
113
- render(
114
- <CheckboxGroup
115
- label="label"
116
- description={
117
- <span>
118
- description with <strong>strong</strong> text
119
- </span>
120
- }
121
- groupName="test"
122
- onChange={() => {}}
123
- selectedValues={[]}
124
- >
125
- <Choice label="a" value="a" aria-labelledby="test-a" />
126
- <Choice label="b" value="b" aria-labelledby="test-b" />
127
- <Choice label="c" value="c" aria-labelledby="test-c" />
128
- </CheckboxGroup>,
129
- );
130
-
131
- // Assert
132
- expect(await screen.findByText("strong")).toBeInTheDocument();
133
- });
134
-
135
- it("should filter out false-y children when rendering", async () => {
136
- // Arrange, Act
137
- render(
138
- <CheckboxGroup
139
- label="label"
140
- description="description"
141
- groupName="test"
142
- onChange={() => {}}
143
- selectedValues={[]}
144
- >
145
- <Choice label="a" value="a" aria-labelledby="test-a" />
146
- {/* eslint-disable-next-line no-constant-condition */}
147
- {false ? (
148
- <Choice label="b" value="b" aria-labelledby="test-b" />
149
- ) : null}
150
- <Choice label="c" value="c" aria-labelledby="test-c" />
151
- {undefined}
152
- {null}
153
- </CheckboxGroup>,
154
- );
155
-
156
- // Assert
157
- const checkboxes = screen.getAllByRole("checkbox");
158
-
159
- expect(checkboxes).toHaveLength(2);
160
- });
161
- });
162
- });