@khanacademy/wonder-blocks-form 4.0.7 → 4.0.9

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 CHANGED
@@ -1,5 +1,29 @@
1
1
  # @khanacademy/wonder-blocks-form
2
2
 
3
+ ## 4.0.9
4
+
5
+ ### Patch Changes
6
+
7
+ - d0f0ce7e: Updates input to StyledInput and uses style prop
8
+ - 1269f6e0: Allow text highlighting on choice components
9
+ - f71343d6: Remove ClickableBehavior from Choice to improve screenreader a11y
10
+ - Updated dependencies [3c400719]
11
+ - Updated dependencies [a6164ed0]
12
+ - @khanacademy/wonder-blocks-core@5.1.0
13
+ - @khanacademy/wonder-blocks-clickable@3.0.9
14
+ - @khanacademy/wonder-blocks-icon@2.0.9
15
+ - @khanacademy/wonder-blocks-layout@2.0.9
16
+ - @khanacademy/wonder-blocks-typography@2.0.9
17
+
18
+ ## 4.0.8
19
+
20
+ ### Patch Changes
21
+
22
+ - @khanacademy/wonder-blocks-clickable@3.0.8
23
+ - @khanacademy/wonder-blocks-icon@2.0.8
24
+ - @khanacademy/wonder-blocks-layout@2.0.8
25
+ - @khanacademy/wonder-blocks-typography@2.0.8
26
+
3
27
  ## 4.0.7
4
28
 
5
29
  ### Patch Changes
@@ -1,16 +1,9 @@
1
1
  import * as React from "react";
2
2
  import type { ChoiceCoreProps } from "../util/types";
3
- type Props = ChoiceCoreProps & {
4
- hovered: boolean;
5
- focused: boolean;
6
- pressed: boolean;
7
- waiting: boolean;
8
- };
9
3
  /**
10
4
  * The internal stateless ☑️ Checkbox
11
5
  */
12
- export default class CheckboxCore extends React.Component<Props> {
6
+ export default class CheckboxCore extends React.Component<ChoiceCoreProps> {
13
7
  handleChange: () => void;
14
8
  render(): React.ReactNode;
15
9
  }
16
- export {};
@@ -6,19 +6,13 @@
6
6
  */
7
7
  import * as React from "react";
8
8
  import type { ChoiceCoreProps } from "../util/types";
9
- declare type Props = {|
10
- ...ChoiceCoreProps,
11
- ...{|
12
- hovered: boolean,
13
- focused: boolean,
14
- pressed: boolean,
15
- waiting: boolean,
16
- |},
17
- |};
9
+
18
10
  /**
19
11
  * The internal stateless ☑️ Checkbox
20
12
  */
21
- declare export default class CheckboxCore extends React.Component<Props> {
13
+ declare export default class CheckboxCore
14
+ extends React.Component<ChoiceCoreProps>
15
+ {
22
16
  handleChange: () => void;
23
17
  render(): React.Node;
24
18
  }
@@ -53,10 +53,9 @@ type DefaultProps = {
53
53
  * (because for Choice, that prop would be auto-populated by CheckboxGroup).
54
54
  */ export default class ChoiceInternal extends React.Component<Props> {
55
55
  static defaultProps: DefaultProps;
56
- handleLabelClick: (event: React.SyntheticEvent) => void;
57
56
  handleClick: () => void;
58
57
  getChoiceCoreComponent(): typeof RadioCore | typeof CheckboxCore;
59
- getLabel(): React.ReactNode;
58
+ getLabel(id: string): React.ReactNode;
60
59
  getDescription(id?: string): React.ReactNode;
61
60
  render(): React.ReactNode;
62
61
  }
@@ -88,10 +88,9 @@ declare type DefaultProps = {|
88
88
  */
89
89
  declare export default class ChoiceInternal extends React.Component<Props> {
90
90
  static defaultProps: DefaultProps;
91
- handleLabelClick: (event: SyntheticEvent<>) => void;
92
91
  handleClick: () => void;
93
92
  getChoiceCoreComponent(): typeof RadioCore | typeof CheckboxCore;
94
- getLabel(): React.Node;
93
+ getLabel(id: string): React.Node;
95
94
  getDescription(id?: string): React.Node;
96
95
  render(): React.Node;
97
96
  }
@@ -1,15 +1,8 @@
1
1
  import * as React from "react";
2
2
  import type { ChoiceCoreProps } from "../util/types";
3
- type Props = ChoiceCoreProps & {
4
- hovered: boolean;
5
- focused: boolean;
6
- pressed: boolean;
7
- waiting: boolean;
8
- };
9
3
  /**
10
4
  * The internal stateless 🔘 Radio button
11
- */ export default class RadioCore extends React.Component<Props> {
5
+ */ export default class RadioCore extends React.Component<ChoiceCoreProps> {
12
6
  handleChange: () => void;
13
7
  render(): React.ReactNode;
14
8
  }
15
- export {};
@@ -6,19 +6,13 @@
6
6
  */
7
7
  import * as React from "react";
8
8
  import type { ChoiceCoreProps } from "../util/types";
9
- declare type Props = {|
10
- ...ChoiceCoreProps,
11
- ...{|
12
- hovered: boolean,
13
- focused: boolean,
14
- pressed: boolean,
15
- waiting: boolean,
16
- |},
17
- |};
9
+
18
10
  /**
19
11
  * The internal stateless 🔘 Radio button
20
12
  */
21
- declare export default class RadioCore extends React.Component<Props> {
13
+ declare export default class RadioCore
14
+ extends React.Component<ChoiceCoreProps>
15
+ {
22
16
  handleChange: () => void;
23
17
  render(): React.Node;
24
18
  }
package/dist/es/index.js CHANGED
@@ -1,8 +1,7 @@
1
1
  import * as React from 'react';
2
- import { StyleSheet, css } from 'aphrodite';
2
+ import { StyleSheet } from 'aphrodite';
3
3
  import Color, { mix, fade } from '@khanacademy/wonder-blocks-color';
4
4
  import { addStyle, UniqueIDProvider, View, IDProvider } from '@khanacademy/wonder-blocks-core';
5
- import { getClickableBehavior } from '@khanacademy/wonder-blocks-clickable';
6
5
  import { Strut } from '@khanacademy/wonder-blocks-layout';
7
6
  import Spacing from '@khanacademy/wonder-blocks-spacing';
8
7
  import { LabelMedium, LabelSmall, styles as styles$6 } from '@khanacademy/wonder-blocks-typography';
@@ -36,7 +35,7 @@ function _objectWithoutPropertiesLoose(source, excluded) {
36
35
  return target;
37
36
  }
38
37
 
39
- const _excluded$4 = ["checked", "disabled", "error", "groupName", "id", "testId", "hovered", "focused", "pressed", "waiting"];
38
+ const _excluded$4 = ["checked", "disabled", "error", "groupName", "id", "testId"];
40
39
  const {
41
40
  blue: blue$1,
42
41
  red: red$1,
@@ -46,7 +45,7 @@ const {
46
45
  offBlack32: offBlack32$1,
47
46
  offBlack50: offBlack50$1
48
47
  } = Color;
49
- const StyledInput$1 = addStyle("input");
48
+ const StyledInput$2 = addStyle("input");
50
49
  const checkboxCheck = {
51
50
  small: "M11.263 4.324a1 1 0 1 1 1.474 1.352l-5.5 6a1 1 0 0 1-1.505-.036l-2.5-3a1 1 0 1 1 1.536-1.28L6.536 9.48l4.727-5.157z"
52
51
  };
@@ -65,18 +64,15 @@ class CheckboxCore extends React.Component {
65
64
  error,
66
65
  groupName,
67
66
  id,
68
- testId,
69
- hovered,
70
- focused,
71
- pressed
67
+ testId
72
68
  } = _this$props,
73
69
  sharedProps = _objectWithoutPropertiesLoose(_this$props, _excluded$4);
74
70
  const stateStyles = _generateStyles$1(checked, error);
75
- const defaultStyle = [sharedStyles$1.inputReset, sharedStyles$1.default, stateStyles.default, !disabled && (pressed ? stateStyles.active : (hovered || focused) && stateStyles.focus), disabled && sharedStyles$1.disabled];
71
+ const defaultStyle = [sharedStyles$1.inputReset, sharedStyles$1.default, !disabled && stateStyles.default, disabled && sharedStyles$1.disabled];
76
72
  const props = {
77
73
  "data-test-id": testId
78
74
  };
79
- return React.createElement(React.Fragment, null, React.createElement(StyledInput$1, _extends({}, sharedProps, {
75
+ return React.createElement(React.Fragment, null, React.createElement(StyledInput$2, _extends({}, sharedProps, {
80
76
  type: "checkbox",
81
77
  "aria-invalid": error,
82
78
  checked: checked,
@@ -151,31 +147,39 @@ const _generateStyles$1 = (checked, error) => {
151
147
  newStyles = {
152
148
  default: {
153
149
  backgroundColor: palette.base,
154
- borderWidth: 0
155
- },
156
- focus: {
157
- boxShadow: `0 0 0 1px ${white$1}, 0 0 0 3px ${palette.base}`
158
- },
159
- active: {
160
- boxShadow: `0 0 0 1px ${white$1}, 0 0 0 3px ${palette.active}`,
161
- background: palette.active
150
+ borderWidth: 0,
151
+ ":focus-visible": {
152
+ boxShadow: `0 0 0 1px ${white$1}, 0 0 0 3px ${palette.base}`
153
+ },
154
+ ":hover": {
155
+ boxShadow: `0 0 0 1px ${white$1}, 0 0 0 3px ${palette.base}`
156
+ },
157
+ ":active": {
158
+ boxShadow: `0 0 0 1px ${white$1}, 0 0 0 3px ${palette.active}`,
159
+ background: palette.active
160
+ }
162
161
  }
163
162
  };
164
163
  } else {
165
164
  newStyles = {
166
165
  default: {
167
166
  backgroundColor: error ? fadedRed$1 : white$1,
168
- borderColor: error ? red$1 : offBlack50$1
169
- },
170
- focus: {
171
- backgroundColor: error ? fadedRed$1 : white$1,
172
- borderColor: palette.base,
173
- borderWidth: 2
174
- },
175
- active: {
176
- backgroundColor: palette.faded,
177
- borderColor: error ? activeRed$1 : blue$1,
178
- borderWidth: 2
167
+ borderColor: error ? red$1 : offBlack50$1,
168
+ ":focus-visible": {
169
+ backgroundColor: error ? fadedRed$1 : white$1,
170
+ borderColor: palette.base,
171
+ borderWidth: 2
172
+ },
173
+ ":hover": {
174
+ backgroundColor: error ? fadedRed$1 : white$1,
175
+ borderColor: palette.base,
176
+ borderWidth: 2
177
+ },
178
+ ":active": {
179
+ backgroundColor: palette.faded,
180
+ borderColor: error ? activeRed$1 : blue$1,
181
+ borderWidth: 2
182
+ }
179
183
  }
180
184
  };
181
185
  }
@@ -183,7 +187,7 @@ const _generateStyles$1 = (checked, error) => {
183
187
  return styles$5[styleKey];
184
188
  };
185
189
 
186
- const _excluded$3 = ["checked", "disabled", "error", "groupName", "id", "testId", "hovered", "focused", "pressed", "waiting"];
190
+ const _excluded$3 = ["checked", "disabled", "error", "groupName", "id", "testId"];
187
191
  const {
188
192
  blue,
189
193
  red,
@@ -193,7 +197,7 @@ const {
193
197
  offBlack32,
194
198
  offBlack50
195
199
  } = Color;
196
- const StyledInput = addStyle("input");
200
+ const StyledInput$1 = addStyle("input");
197
201
  class RadioCore extends React.Component {
198
202
  constructor(...args) {
199
203
  super(...args);
@@ -209,18 +213,15 @@ class RadioCore extends React.Component {
209
213
  error,
210
214
  groupName,
211
215
  id,
212
- testId,
213
- hovered,
214
- focused,
215
- pressed
216
+ testId
216
217
  } = _this$props,
217
218
  sharedProps = _objectWithoutPropertiesLoose(_this$props, _excluded$3);
218
219
  const stateStyles = _generateStyles(checked, error);
219
- const defaultStyle = [sharedStyles.inputReset, sharedStyles.default, stateStyles.default, !disabled && (pressed ? stateStyles.active : (hovered || focused) && stateStyles.focus), disabled && sharedStyles.disabled];
220
+ const defaultStyle = [sharedStyles.inputReset, sharedStyles.default, !disabled && stateStyles.default, disabled && sharedStyles.disabled];
220
221
  const props = {
221
222
  "data-test-id": testId
222
223
  };
223
- return React.createElement(React.Fragment, null, React.createElement(StyledInput, _extends({}, sharedProps, {
224
+ return React.createElement(React.Fragment, null, React.createElement(StyledInput$1, _extends({}, sharedProps, {
224
225
  type: "radio",
225
226
  "aria-invalid": error,
226
227
  checked: checked,
@@ -298,31 +299,39 @@ const _generateStyles = (checked, error) => {
298
299
  default: {
299
300
  backgroundColor: white,
300
301
  borderColor: palette.base,
301
- borderWidth: size / 4
302
- },
303
- focus: {
304
- boxShadow: `0 0 0 1px ${white}, 0 0 0 3px ${palette.base}`
305
- },
306
- active: {
307
- boxShadow: `0 0 0 1px ${white}, 0 0 0 3px ${palette.active}`,
308
- borderColor: palette.active
302
+ borderWidth: size / 4,
303
+ ":focus-visible": {
304
+ boxShadow: `0 0 0 1px ${white}, 0 0 0 3px ${palette.base}`
305
+ },
306
+ ":hover": {
307
+ boxShadow: `0 0 0 1px ${white}, 0 0 0 3px ${palette.base}`
308
+ },
309
+ ":active": {
310
+ boxShadow: `0 0 0 1px ${white}, 0 0 0 3px ${palette.active}`,
311
+ borderColor: palette.active
312
+ }
309
313
  }
310
314
  };
311
315
  } else {
312
316
  newStyles = {
313
317
  default: {
314
318
  backgroundColor: error ? fadedRed : white,
315
- borderColor: error ? red : offBlack50
316
- },
317
- focus: {
318
- backgroundColor: error ? fadedRed : white,
319
- borderColor: palette.base,
320
- borderWidth: 2
321
- },
322
- active: {
323
- backgroundColor: palette.faded,
324
- borderColor: error ? activeRed : blue,
325
- borderWidth: 2
319
+ borderColor: error ? red : offBlack50,
320
+ ":focus-visible": {
321
+ backgroundColor: error ? fadedRed : white,
322
+ borderColor: palette.base,
323
+ borderWidth: 2
324
+ },
325
+ ":hover": {
326
+ backgroundColor: error ? fadedRed : white,
327
+ borderColor: palette.base,
328
+ borderWidth: 2
329
+ },
330
+ ":active": {
331
+ backgroundColor: palette.faded,
332
+ borderColor: error ? activeRed : blue,
333
+ borderWidth: 2
334
+ }
326
335
  }
327
336
  };
328
337
  }
@@ -330,13 +339,10 @@ const _generateStyles = (checked, error) => {
330
339
  return styles$4[styleKey];
331
340
  };
332
341
 
333
- const _excluded$2 = ["label", "description", "onChange", "style", "className", "variant"];
342
+ const _excluded$2 = ["label", "description", "id", "onChange", "style", "className", "variant"];
334
343
  class ChoiceInternal extends React.Component {
335
344
  constructor(...args) {
336
345
  super(...args);
337
- this.handleLabelClick = event => {
338
- event.preventDefault();
339
- };
340
346
  this.handleClick = () => {
341
347
  const {
342
348
  checked,
@@ -356,17 +362,15 @@ class ChoiceInternal extends React.Component {
356
362
  return CheckboxCore;
357
363
  }
358
364
  }
359
- getLabel() {
365
+ getLabel(id) {
360
366
  const {
361
367
  disabled,
362
- id,
363
368
  label
364
369
  } = this.props;
365
370
  return React.createElement(LabelMedium, {
366
371
  style: [styles$3.label, disabled && styles$3.disabledLabel]
367
372
  }, React.createElement("label", {
368
- htmlFor: id,
369
- onClick: this.handleLabelClick
373
+ htmlFor: id
370
374
  }, label));
371
375
  }
372
376
  getDescription(id) {
@@ -383,36 +387,31 @@ class ChoiceInternal extends React.Component {
383
387
  {
384
388
  label,
385
389
  description,
390
+ id,
386
391
  style,
387
- className,
388
- variant
392
+ className
389
393
  } = _this$props,
390
394
  coreProps = _objectWithoutPropertiesLoose(_this$props, _excluded$2);
391
395
  const ChoiceCore = this.getChoiceCoreComponent();
392
- const ClickableBehavior = getClickableBehavior();
393
396
  return React.createElement(UniqueIDProvider, {
394
397
  mockOnFirstRender: true,
395
398
  scope: "choice"
396
399
  }, ids => {
400
+ const uniqueId = id || ids.get("main");
397
401
  const descriptionId = description ? ids.get("description") : undefined;
398
402
  return React.createElement(View, {
399
403
  style: style,
400
404
  className: className
401
- }, React.createElement(ClickableBehavior, {
402
- disabled: coreProps.disabled,
403
- onClick: this.handleClick,
404
- role: variant
405
- }, (state, childrenProps) => {
406
- return React.createElement(View, _extends({
407
- style: styles$3.wrapper
408
- }, childrenProps, {
409
- tabIndex: -1
410
- }), React.createElement(ChoiceCore, _extends({}, coreProps, state, {
411
- "aria-describedby": descriptionId
412
- })), React.createElement(Strut, {
413
- size: Spacing.xSmall_8
414
- }), label && this.getLabel());
415
- }), description && this.getDescription(descriptionId));
405
+ }, React.createElement(View, {
406
+ style: styles$3.wrapper,
407
+ tabIndex: -1
408
+ }, React.createElement(ChoiceCore, _extends({}, coreProps, {
409
+ id: uniqueId,
410
+ "aria-describedby": descriptionId,
411
+ onClick: this.handleClick
412
+ })), React.createElement(Strut, {
413
+ size: Spacing.xSmall_8
414
+ }), label && this.getLabel(uniqueId)), description && this.getDescription(descriptionId));
416
415
  });
417
416
  }
418
417
  }
@@ -428,7 +427,6 @@ const styles$3 = StyleSheet.create({
428
427
  outline: "none"
429
428
  },
430
429
  label: {
431
- userSelect: "none",
432
430
  marginTop: -2
433
431
  },
434
432
  disabledLabel: {
@@ -626,6 +624,7 @@ class RadioGroup extends React.Component {
626
624
 
627
625
  const _excluded = ["id", "type", "value", "disabled", "onKeyDown", "placeholder", "light", "style", "testId", "readOnly", "autoComplete", "forwardedRef", "onFocus", "onBlur", "onValidate", "validate", "onChange", "required"];
628
626
  const defaultErrorMessage = "This field is required.";
627
+ const StyledInput = addStyle("input");
629
628
  class TextField extends React.Component {
630
629
  constructor(props) {
631
630
  super(props);
@@ -718,8 +717,8 @@ class TextField extends React.Component {
718
717
  forwardedRef
719
718
  } = _this$props,
720
719
  otherProps = _objectWithoutPropertiesLoose(_this$props, _excluded);
721
- return React.createElement("input", _extends({
722
- className: css([styles$1.input, styles$6.LabelMedium, styles$1.default, disabled ? styles$1.disabled : this.state.focused ? [styles$1.focused, light && styles$1.defaultLight] : this.state.error && [styles$1.error, light && styles$1.errorLight], style && style]),
720
+ return React.createElement(StyledInput, _extends({
721
+ style: [styles$1.input, styles$6.LabelMedium, styles$1.default, disabled ? styles$1.disabled : this.state.focused ? [styles$1.focused, light && styles$1.defaultLight] : !!this.state.error && [styles$1.error, light && styles$1.errorLight], !!this.state.error && styles$1.error, style && style],
723
722
  id: id,
724
723
  type: type,
725
724
  placeholder: placeholder,