@nypl/design-system-react-components 0.25.9 → 0.25.12

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 (163) hide show
  1. package/CHANGELOG.md +96 -0
  2. package/README.md +4 -16
  3. package/dist/components/Breadcrumbs/BreadcrumbsTypes.d.ts +1 -0
  4. package/dist/components/DatePicker/DatePicker.d.ts +1 -1
  5. package/dist/components/Fieldset/Fieldset.d.ts +1 -3
  6. package/dist/components/Form/Form.d.ts +13 -12
  7. package/dist/components/Form/FormTypes.d.ts +2 -2
  8. package/dist/components/HorizontalRule/HorizontalRule.d.ts +1 -1
  9. package/dist/components/Icons/IconTypes.d.ts +9 -7
  10. package/dist/components/List/List.d.ts +1 -1
  11. package/dist/components/Logo/LogoSvgs.d.ts +23 -1
  12. package/dist/components/Logo/LogoTypes.d.ts +23 -1
  13. package/dist/components/Notification/Notification.d.ts +2 -0
  14. package/dist/components/Pagination/Pagination.d.ts +6 -2
  15. package/dist/components/RadioGroup/RadioGroup.d.ts +3 -3
  16. package/dist/components/SearchBar/SearchBar.d.ts +6 -6
  17. package/dist/components/Select/Select.d.ts +4 -0
  18. package/dist/components/Table/Table.d.ts +9 -3
  19. package/dist/components/Template/Template.d.ts +24 -5
  20. package/dist/design-system-react-components.cjs.development.js +2063 -548
  21. package/dist/design-system-react-components.cjs.development.js.map +1 -1
  22. package/dist/design-system-react-components.cjs.production.min.js +1 -1
  23. package/dist/design-system-react-components.cjs.production.min.js.map +1 -1
  24. package/dist/design-system-react-components.esm.js +2056 -554
  25. package/dist/design-system-react-components.esm.js.map +1 -1
  26. package/dist/index.d.ts +4 -4
  27. package/dist/resources.scss +0 -2
  28. package/dist/styles.css +1 -1
  29. package/dist/theme/components/breadcrumb.d.ts +4 -1
  30. package/dist/theme/components/checkbox.d.ts +0 -2
  31. package/dist/theme/components/customTable.d.ts +12 -3
  32. package/dist/theme/components/fieldset.d.ts +2 -0
  33. package/dist/theme/components/global.d.ts +15 -14
  34. package/dist/theme/components/globalMixins.d.ts +8 -8
  35. package/dist/theme/components/list.d.ts +6 -0
  36. package/dist/theme/components/notification.d.ts +16 -4
  37. package/dist/theme/components/radio.d.ts +3 -2
  38. package/dist/theme/components/searchBar.d.ts +4 -0
  39. package/dist/theme/components/select.d.ts +2 -9
  40. package/dist/theme/components/slider.d.ts +8 -4
  41. package/dist/theme/components/structuredContent.d.ts +9 -9
  42. package/dist/theme/components/textInput.d.ts +10 -12
  43. package/dist/theme/components/toggle.d.ts +6 -2
  44. package/dist/theme/foundations/global.d.ts +31 -3
  45. package/dist/utils/utils.d.ts +10 -0
  46. package/package.json +40 -36
  47. package/src/components/Accordion/Accordion.stories.mdx +1 -1
  48. package/src/components/Accordion/Accordion.test.tsx +45 -1
  49. package/src/components/Accordion/Accordion.tsx +20 -8
  50. package/src/components/Accordion/__snapshots__/Accordion.test.tsx.snap +243 -0
  51. package/src/components/Breadcrumbs/Breadcrumbs.stories.mdx +30 -2
  52. package/src/components/Breadcrumbs/Breadcrumbs.test.tsx +25 -0
  53. package/src/components/Breadcrumbs/Breadcrumbs.tsx +9 -3
  54. package/src/components/Breadcrumbs/BreadcrumbsTypes.tsx +1 -0
  55. package/src/components/Breadcrumbs/__snapshots__/Breadcrumbs.test.tsx.snap +104 -5
  56. package/src/components/Card/Card.stories.mdx +1 -1
  57. package/src/components/Card/Card.tsx +4 -1
  58. package/src/components/Card/__snapshots__/Card.test.tsx.snap +1 -1
  59. package/src/components/Chakra/Flex.stories.mdx +113 -0
  60. package/src/components/Checkbox/Checkbox.stories.mdx +1 -1
  61. package/src/components/Checkbox/Checkbox.tsx +1 -0
  62. package/src/components/Checkbox/__snapshots__/Checkbox.test.tsx.snap +6 -6
  63. package/src/components/CheckboxGroup/CheckboxGroup.stories.mdx +1 -1
  64. package/src/components/CheckboxGroup/__snapshots__/CheckboxGroup.test.tsx.snap +18 -18
  65. package/src/components/DatePicker/DatePicker.stories.mdx +1 -1
  66. package/src/components/DatePicker/DatePicker.test.tsx +6 -6
  67. package/src/components/DatePicker/DatePicker.tsx +12 -10
  68. package/src/components/DatePicker/__snapshots__/DatePicker.test.tsx.snap +28 -20
  69. package/src/components/Fieldset/Fieldset.stories.mdx +1 -1
  70. package/src/components/Fieldset/Fieldset.tsx +2 -4
  71. package/src/components/Form/Form.stories.mdx +34 -16
  72. package/src/components/Form/Form.test.tsx +92 -3
  73. package/src/components/Form/Form.tsx +25 -21
  74. package/src/components/Form/FormTypes.tsx +2 -2
  75. package/src/components/Form/__snapshots__/Form.test.tsx.snap +0 -1
  76. package/src/components/HelperErrorText/HelperErrorText.stories.mdx +1 -1
  77. package/src/components/Hero/Hero.stories.mdx +1 -1
  78. package/src/components/HorizontalRule/HorizontalRule.stories.mdx +3 -2
  79. package/src/components/HorizontalRule/HorizontalRule.tsx +2 -2
  80. package/src/components/HorizontalRule/__snapshots__/HorizontalRule.test.tsx.snap +4 -4
  81. package/src/components/Icons/Icon.stories.mdx +1 -1
  82. package/src/components/Icons/Icon.test.tsx +1 -1
  83. package/src/components/Icons/Icon.tsx +1 -1
  84. package/src/components/Icons/IconTypes.tsx +8 -6
  85. package/src/components/List/List.stories.mdx +24 -5
  86. package/src/components/List/List.test.tsx +1 -1
  87. package/src/components/List/List.tsx +2 -2
  88. package/src/components/List/__snapshots__/List.test.tsx.snap +3 -1
  89. package/src/components/Logo/Logo.stories.mdx +7 -5
  90. package/src/components/Logo/LogoSvgs.tsx +45 -1
  91. package/src/components/Logo/LogoTypes.tsx +22 -0
  92. package/src/components/Notification/Notification.stories.mdx +73 -1
  93. package/src/components/Notification/Notification.test.tsx +64 -5
  94. package/src/components/Notification/Notification.tsx +21 -11
  95. package/src/components/Notification/__snapshots__/Notification.test.tsx.snap +103 -8
  96. package/src/components/Pagination/Pagination.stories.mdx +54 -12
  97. package/src/components/Pagination/Pagination.test.tsx +63 -5
  98. package/src/components/Pagination/Pagination.tsx +46 -24
  99. package/src/components/Pagination/__snapshots__/Pagination.test.tsx.snap +3 -3
  100. package/src/components/Radio/Radio.stories.mdx +1 -1
  101. package/src/components/Radio/Radio.tsx +1 -0
  102. package/src/components/Radio/__snapshots__/Radio.test.tsx.snap +5 -5
  103. package/src/components/RadioGroup/RadioGroup.stories.mdx +1 -1
  104. package/src/components/RadioGroup/RadioGroup.test.tsx +13 -11
  105. package/src/components/RadioGroup/RadioGroup.tsx +88 -89
  106. package/src/components/RadioGroup/__snapshots__/RadioGroup.test.tsx.snap +18 -18
  107. package/src/components/SearchBar/SearchBar.Test.tsx +124 -28
  108. package/src/components/SearchBar/SearchBar.stories.mdx +9 -6
  109. package/src/components/SearchBar/SearchBar.tsx +24 -23
  110. package/src/components/Select/Select.stories.mdx +1 -1
  111. package/src/components/Select/Select.test.tsx +89 -0
  112. package/src/components/Select/Select.tsx +11 -2
  113. package/src/components/Select/__snapshots__/Select.test.tsx.snap +545 -0
  114. package/src/components/Slider/Slider.stories.mdx +1 -1
  115. package/src/components/Slider/Slider.tsx +4 -1
  116. package/src/components/Slider/__snapshots__/Slider.test.tsx.snap +7 -0
  117. package/src/components/StructuredContent/StructuredContent.stories.mdx +1 -1
  118. package/src/components/StyleGuide/Bidirectionality.stories.mdx +4 -4
  119. package/src/components/StyleGuide/Colors.stories.mdx +33 -18
  120. package/src/components/Table/Table.stories.mdx +118 -19
  121. package/src/components/Table/Table.test.tsx +80 -3
  122. package/src/components/Table/Table.tsx +26 -16
  123. package/src/components/Table/__snapshots__/Table.test.tsx.snap +1179 -0
  124. package/src/components/Tabs/Tabs.stories.mdx +1 -1
  125. package/src/components/Tabs/Tabs.test.tsx +21 -5
  126. package/src/components/Tabs/Tabs.tsx +35 -20
  127. package/src/components/Tabs/__snapshots__/Tabs.test.tsx.snap +195 -0
  128. package/src/components/Template/Template.stories.mdx +79 -4
  129. package/src/components/Template/Template.test.tsx +65 -3
  130. package/src/components/Template/Template.tsx +60 -14
  131. package/src/components/Template/__snapshots__/Template.test.tsx.snap +94 -1
  132. package/src/components/TextInput/TextInput.stories.mdx +1 -1
  133. package/src/components/Toggle/Toggle.stories.mdx +1 -1
  134. package/src/components/Toggle/Toggle.tsx +2 -1
  135. package/src/components/Toggle/__snapshots__/Toggle.test.tsx.snap +4 -4
  136. package/src/docs/Chakra.stories.mdx +1 -1
  137. package/src/index.ts +8 -2
  138. package/src/styles/base/_place-holder.scss +2 -0
  139. package/src/styles.scss +0 -2
  140. package/src/theme/components/breadcrumb.ts +5 -1
  141. package/src/theme/components/checkbox.ts +3 -7
  142. package/src/theme/components/customTable.ts +16 -3
  143. package/src/theme/components/fieldset.ts +2 -0
  144. package/src/theme/components/global.ts +19 -16
  145. package/src/theme/components/globalMixins.ts +8 -8
  146. package/src/theme/components/list.ts +6 -2
  147. package/src/theme/components/notification.ts +21 -8
  148. package/src/theme/components/radio.ts +3 -6
  149. package/src/theme/components/searchBar.ts +4 -0
  150. package/src/theme/components/select.ts +3 -3
  151. package/src/theme/components/slider.ts +12 -9
  152. package/src/theme/components/structuredContent.ts +26 -6
  153. package/src/theme/components/textInput.ts +3 -2
  154. package/src/theme/components/toggle.ts +42 -38
  155. package/src/theme/foundations/colors.ts +19 -12
  156. package/src/theme/foundations/global.ts +17 -5
  157. package/src/theme/foundations/typography.ts +2 -2
  158. package/src/utils/componentCategories.ts +2 -1
  159. package/src/utils/utils.ts +28 -0
  160. package/dist/components/Pagination/Pagination.stories.d.ts +0 -13
  161. package/src/components/Pagination/Pagination.stories.tsx +0 -54
  162. package/src/styles/base/_03-base.scss +0 -25
  163. package/src/styles/base/_04-focus.scss +0 -22
@@ -16,8 +16,6 @@ import { RadioGroupLayoutTypes } from "./RadioGroupLayoutTypes";
16
16
  import generateUUID from "../../helpers/generateUUID";
17
17
 
18
18
  export interface RadioGroupProps {
19
- /** Any child node passed to the component. */
20
- children: React.ReactNode;
21
19
  /** Additional class name. */
22
20
  className?: string;
23
21
  /** Populates the initial value of the input */
@@ -58,101 +56,102 @@ export const onChangeDefault = () => {
58
56
  return;
59
57
  };
60
58
 
61
- const RadioGroup = React.forwardRef<HTMLInputElement, RadioGroupProps>(
62
- (props, ref?) => {
63
- const {
64
- children,
65
- className = "",
66
- defaultValue,
67
- helperText,
68
- id = generateUUID(),
69
- invalidText,
70
- isDisabled = false,
71
- isInvalid = false,
72
- isRequired = false,
73
- labelText,
74
- layout = RadioGroupLayoutTypes.Column,
75
- name,
76
- onChange = onChangeDefault,
77
- optReqFlag = true,
78
- showHelperInvalidText = true,
79
- showLabel = true,
80
- } = props;
81
- const footnote: HelperErrorTextType = isInvalid ? invalidText : helperText;
82
- const spacingProp =
83
- layout === RadioGroupLayoutTypes.Column ? spacing.s : spacing.l;
84
- const newChildren = [];
59
+ const RadioGroup = React.forwardRef<
60
+ HTMLInputElement,
61
+ React.PropsWithChildren<RadioGroupProps>
62
+ >((props, ref?) => {
63
+ const {
64
+ children,
65
+ className = "",
66
+ defaultValue,
67
+ helperText,
68
+ id = generateUUID(),
69
+ invalidText,
70
+ isDisabled = false,
71
+ isInvalid = false,
72
+ isRequired = false,
73
+ labelText,
74
+ layout = RadioGroupLayoutTypes.Column,
75
+ name,
76
+ onChange = onChangeDefault,
77
+ optReqFlag = true,
78
+ showHelperInvalidText = true,
79
+ showLabel = true,
80
+ } = props;
81
+ const footnote: HelperErrorTextType = isInvalid ? invalidText : helperText;
82
+ const spacingProp =
83
+ layout === RadioGroupLayoutTypes.Column ? spacing.s : spacing.l;
84
+ const newChildren = [];
85
85
 
86
- // Use Chakra's RadioGroup hook to set and get the proper props
87
- // or the custom components.
88
- const { getRootProps, getRadioProps } = useRadioGroup({
89
- name,
90
- defaultValue,
91
- onChange,
92
- });
93
- const radioGroupProps = getRootProps();
86
+ // Use Chakra's RadioGroup hook to set and get the proper props
87
+ // or the custom components.
88
+ const { getRootProps, getRadioProps } = useRadioGroup({
89
+ name,
90
+ defaultValue,
91
+ onChange,
92
+ });
93
+ const radioGroupProps = getRootProps();
94
94
 
95
- // Go through the Radio children and update them as needed.
96
- React.Children.map(children, (child: React.ReactElement, i) => {
97
- if (child.type !== Radio) {
98
- // Special case for Storybook MDX documentation.
99
- if (child.props.mdxType && child.props.mdxType === "Radio") {
100
- noop();
101
- } else {
102
- console.warn(
103
- "Only `Radio` components are allowed inside the `RadioGroup` component."
104
- );
105
- }
95
+ // Go through the Radio children and update them as needed.
96
+ React.Children.map(children, (child: React.ReactElement, i) => {
97
+ if (child.type !== Radio) {
98
+ // Special case for Storybook MDX documentation.
99
+ if (child.props.mdxType && child.props.mdxType === "Radio") {
100
+ noop();
101
+ } else {
102
+ console.warn(
103
+ "Only `Radio` components are allowed inside the `RadioGroup` component."
104
+ );
106
105
  }
106
+ }
107
107
 
108
- const chakraRadioProps = getRadioProps({
109
- value: child.props.value,
110
- } as any);
108
+ const chakraRadioProps = getRadioProps({
109
+ value: child.props.value,
110
+ } as any);
111
111
 
112
- if (child !== undefined && child !== null) {
113
- const newProps = { key: i, isDisabled, isInvalid, isRequired };
114
- if (child.props.value === defaultValue) {
115
- newProps["checked"] = true;
116
- }
117
- newChildren.push(
118
- React.cloneElement(child, { ...newProps, ...chakraRadioProps })
119
- );
112
+ if (child !== undefined && child !== null) {
113
+ const newProps = { key: i, isDisabled, isInvalid, isRequired };
114
+ if (child.props.value === defaultValue) {
115
+ newProps["checked"] = true;
120
116
  }
121
- });
117
+ newChildren.push(
118
+ React.cloneElement(child, { ...newProps, ...chakraRadioProps })
119
+ );
120
+ }
121
+ });
122
122
 
123
- // Get the Chakra-based styles for the custom elements in this component.
124
- const styles = useMultiStyleConfig("RadioGroup", {});
123
+ // Get the Chakra-based styles for the custom elements in this component.
124
+ const styles = useMultiStyleConfig("RadioGroup", {});
125
125
 
126
- return (
127
- <Fieldset
128
- id={`radio-group-${id}`}
129
- className={className}
130
- isLegendHidden={!showLabel}
131
- legendText={labelText}
132
- optReqFlag={optReqFlag}
126
+ return (
127
+ <Fieldset
128
+ className={className}
129
+ id={`radio-group-${id}`}
130
+ isLegendHidden={!showLabel}
131
+ legendText={labelText}
132
+ optReqFlag={optReqFlag}
133
+ >
134
+ <Stack
135
+ aria-label={!showLabel ? labelText : null}
136
+ direction={[layout]}
137
+ spacing={spacingProp}
138
+ ref={ref}
139
+ {...radioGroupProps}
140
+ sx={styles.stack}
133
141
  >
134
- <Stack
135
- direction={[layout]}
136
- spacing={spacingProp}
137
- ref={ref}
138
- aria-label={!showLabel ? labelText : null}
139
- {...radioGroupProps}
140
- sx={styles.stack}
141
- >
142
- {newChildren}
143
- </Stack>
144
- {footnote && showHelperInvalidText && (
145
- <Box __css={styles.helper}>
146
- <HelperErrorText
147
- id={`${id}-helperErrorText`}
148
- isInvalid={isInvalid}
149
- text={footnote}
150
- />
151
- </Box>
152
- )}
153
- </Fieldset>
154
- );
155
- }
156
- );
142
+ {newChildren}
143
+ </Stack>
144
+ {footnote && showHelperInvalidText && (
145
+ <Box __css={styles.helper}>
146
+ <HelperErrorText
147
+ id={`${id}-helperErrorText`}
148
+ isInvalid={isInvalid}
149
+ text={footnote}
150
+ />
151
+ </Box>
152
+ )}
153
+ </Fieldset>
154
+ );
155
+ });
157
156
 
158
157
  export default RadioGroup;
@@ -19,7 +19,7 @@ exports[`Radio Button renders the UI snapshot correctly 1`] = `
19
19
  role="radiogroup"
20
20
  >
21
21
  <label
22
- className="chakra-radio css-78joka"
22
+ className="chakra-radio css-13p0l12"
23
23
  >
24
24
  <input
25
25
  checked={false}
@@ -66,7 +66,7 @@ exports[`Radio Button renders the UI snapshot correctly 1`] = `
66
66
  </span>
67
67
  </label>
68
68
  <label
69
- className="chakra-radio css-78joka"
69
+ className="chakra-radio css-13p0l12"
70
70
  >
71
71
  <input
72
72
  checked={false}
@@ -135,7 +135,7 @@ exports[`Radio Button renders the UI snapshot correctly 2`] = `
135
135
  role="radiogroup"
136
136
  >
137
137
  <label
138
- className="chakra-radio css-78joka"
138
+ className="chakra-radio css-13p0l12"
139
139
  >
140
140
  <input
141
141
  checked={false}
@@ -182,7 +182,7 @@ exports[`Radio Button renders the UI snapshot correctly 2`] = `
182
182
  </span>
183
183
  </label>
184
184
  <label
185
- className="chakra-radio css-78joka"
185
+ className="chakra-radio css-13p0l12"
186
186
  >
187
187
  <input
188
188
  checked={false}
@@ -251,7 +251,7 @@ exports[`Radio Button renders the UI snapshot correctly 3`] = `
251
251
  role="radiogroup"
252
252
  >
253
253
  <label
254
- className="chakra-radio css-78joka"
254
+ className="chakra-radio css-13p0l12"
255
255
  >
256
256
  <input
257
257
  checked={false}
@@ -298,7 +298,7 @@ exports[`Radio Button renders the UI snapshot correctly 3`] = `
298
298
  </span>
299
299
  </label>
300
300
  <label
301
- className="chakra-radio css-78joka"
301
+ className="chakra-radio css-13p0l12"
302
302
  >
303
303
  <input
304
304
  checked={false}
@@ -367,7 +367,7 @@ exports[`Radio Button renders the UI snapshot correctly 4`] = `
367
367
  role="radiogroup"
368
368
  >
369
369
  <label
370
- className="chakra-radio css-78joka"
370
+ className="chakra-radio css-13p0l12"
371
371
  >
372
372
  <input
373
373
  checked={false}
@@ -414,7 +414,7 @@ exports[`Radio Button renders the UI snapshot correctly 4`] = `
414
414
  </span>
415
415
  </label>
416
416
  <label
417
- className="chakra-radio css-78joka"
417
+ className="chakra-radio css-13p0l12"
418
418
  >
419
419
  <input
420
420
  checked={false}
@@ -499,7 +499,7 @@ exports[`Radio Button renders the UI snapshot correctly 5`] = `
499
499
  role="radiogroup"
500
500
  >
501
501
  <label
502
- className="chakra-radio css-78joka"
502
+ className="chakra-radio css-13p0l12"
503
503
  >
504
504
  <input
505
505
  checked={false}
@@ -546,7 +546,7 @@ exports[`Radio Button renders the UI snapshot correctly 5`] = `
546
546
  </span>
547
547
  </label>
548
548
  <label
549
- className="chakra-radio css-78joka"
549
+ className="chakra-radio css-13p0l12"
550
550
  >
551
551
  <input
552
552
  checked={false}
@@ -610,7 +610,7 @@ exports[`Radio Button renders the UI snapshot correctly 6`] = `
610
610
  role="radiogroup"
611
611
  >
612
612
  <label
613
- className="chakra-radio css-78joka"
613
+ className="chakra-radio css-13p0l12"
614
614
  >
615
615
  <input
616
616
  checked={false}
@@ -657,7 +657,7 @@ exports[`Radio Button renders the UI snapshot correctly 6`] = `
657
657
  </span>
658
658
  </label>
659
659
  <label
660
- className="chakra-radio css-78joka"
660
+ className="chakra-radio css-13p0l12"
661
661
  >
662
662
  <input
663
663
  checked={false}
@@ -726,7 +726,7 @@ exports[`Radio Button renders the UI snapshot correctly 7`] = `
726
726
  role="radiogroup"
727
727
  >
728
728
  <label
729
- className="chakra-radio css-78joka"
729
+ className="chakra-radio css-13p0l12"
730
730
  >
731
731
  <input
732
732
  aria-required={true}
@@ -774,7 +774,7 @@ exports[`Radio Button renders the UI snapshot correctly 7`] = `
774
774
  </span>
775
775
  </label>
776
776
  <label
777
- className="chakra-radio css-78joka"
777
+ className="chakra-radio css-13p0l12"
778
778
  >
779
779
  <input
780
780
  aria-required={true}
@@ -844,7 +844,7 @@ exports[`Radio Button renders the UI snapshot correctly 8`] = `
844
844
  role="radiogroup"
845
845
  >
846
846
  <label
847
- className="chakra-radio css-78joka"
847
+ className="chakra-radio css-13p0l12"
848
848
  data-invalid=""
849
849
  >
850
850
  <input
@@ -895,7 +895,7 @@ exports[`Radio Button renders the UI snapshot correctly 8`] = `
895
895
  </span>
896
896
  </label>
897
897
  <label
898
- className="chakra-radio css-78joka"
898
+ className="chakra-radio css-13p0l12"
899
899
  data-invalid=""
900
900
  >
901
901
  <input
@@ -968,7 +968,7 @@ exports[`Radio Button renders the UI snapshot correctly 9`] = `
968
968
  role="radiogroup"
969
969
  >
970
970
  <label
971
- className="chakra-radio css-78joka"
971
+ className="chakra-radio css-13p0l12"
972
972
  data-disabled=""
973
973
  >
974
974
  <input
@@ -1019,7 +1019,7 @@ exports[`Radio Button renders the UI snapshot correctly 9`] = `
1019
1019
  </span>
1020
1020
  </label>
1021
1021
  <label
1022
- className="chakra-radio css-78joka"
1022
+ className="chakra-radio css-13p0l12"
1023
1023
  data-disabled=""
1024
1024
  >
1025
1025
  <input
@@ -4,7 +4,7 @@ import { axe } from "jest-axe";
4
4
  import userEvent from "@testing-library/user-event";
5
5
  import renderer from "react-test-renderer";
6
6
 
7
- import SearchBar from "./SearchBar";
7
+ import SearchBar, { SelectProps, TextInputProps } from "./SearchBar";
8
8
 
9
9
  const optionsGroup = [
10
10
  "Art",
@@ -18,16 +18,17 @@ const optionsGroup = [
18
18
  "Tools",
19
19
  "Villagers",
20
20
  ];
21
- const selectProps = {
21
+ const selectProps: SelectProps = {
22
22
  name: "selectName",
23
23
  labelText: "Select a category",
24
24
  optionsData: optionsGroup,
25
25
  };
26
- const textInputProps = {
26
+ const textInputProps: TextInputProps = {
27
27
  labelText: "Item Search",
28
28
  name: "textInputName",
29
29
  placeholder: "Item Search",
30
30
  };
31
+ const labelText = "SearchBar label";
31
32
  const helperText = "Search for items in Animal Crossing New Horizons";
32
33
  const invalidText = "Could not find the item :(";
33
34
 
@@ -38,7 +39,21 @@ describe("SearchBar Accessibility", () => {
38
39
  helperText={helperText}
39
40
  id="id"
40
41
  invalidText={invalidText}
41
- labelText="Searchbar"
42
+ labelText={labelText}
43
+ onSubmit={jest.fn()}
44
+ textInputProps={textInputProps}
45
+ />
46
+ );
47
+ expect(await axe(container)).toHaveNoViolations();
48
+ });
49
+
50
+ it("passes axe accessibility test with a Select component", async () => {
51
+ const { container } = render(
52
+ <SearchBar
53
+ helperText={helperText}
54
+ id="id"
55
+ invalidText={invalidText}
56
+ labelText={labelText}
42
57
  onSubmit={jest.fn()}
43
58
  selectProps={selectProps}
44
59
  textInputProps={textInputProps}
@@ -52,12 +67,16 @@ describe("SearchBar", () => {
52
67
  const searchBarSubmit = jest.fn();
53
68
  const buttonCallback = jest.fn();
54
69
 
70
+ beforeEach(() => {
71
+ jest.clearAllMocks();
72
+ });
73
+
55
74
  it("renders the basic form", () => {
56
75
  render(
57
76
  <SearchBar
58
77
  helperText={helperText}
59
78
  id="id"
60
- labelText="searchbar"
79
+ labelText={labelText}
61
80
  onSubmit={searchBarSubmit}
62
81
  textInputProps={textInputProps}
63
82
  />
@@ -65,7 +84,7 @@ describe("SearchBar", () => {
65
84
  expect(screen.getByRole("search")).toBeInTheDocument();
66
85
  expect(screen.getByRole("search")).toHaveAttribute(
67
86
  "aria-label",
68
- "searchbar"
87
+ `${labelText} - ${helperText}`
69
88
  );
70
89
  expect(screen.getByPlaceholderText("Item Search")).toBeInTheDocument();
71
90
  expect(screen.getByRole("button")).toBeInTheDocument();
@@ -76,7 +95,7 @@ describe("SearchBar", () => {
76
95
  <SearchBar
77
96
  helperText={helperText}
78
97
  id="id"
79
- labelText="searchbar"
98
+ labelText={labelText}
80
99
  onSubmit={searchBarSubmit}
81
100
  selectProps={selectProps}
82
101
  textInputProps={textInputProps}
@@ -93,7 +112,7 @@ describe("SearchBar", () => {
93
112
  id="id"
94
113
  invalidText={invalidText}
95
114
  isInvalid
96
- labelText="searchbar"
115
+ labelText={labelText}
97
116
  onSubmit={searchBarSubmit}
98
117
  selectProps={selectProps}
99
118
  textInputProps={textInputProps}
@@ -110,7 +129,7 @@ describe("SearchBar", () => {
110
129
  id="id"
111
130
  invalidText={invalidText}
112
131
  isInvalid
113
- labelText="searchbar"
132
+ labelText={labelText}
114
133
  onSubmit={searchBarSubmit}
115
134
  selectProps={selectProps}
116
135
  textInputProps={textInputProps}
@@ -121,38 +140,115 @@ describe("SearchBar", () => {
121
140
  ).not.toBeInTheDocument();
122
141
  });
123
142
 
143
+ it("calls the TextInput onChange callback function", () => {
144
+ textInputProps.onChange = jest.fn();
145
+
146
+ render(
147
+ <SearchBar
148
+ helperText={helperText}
149
+ id="id"
150
+ labelText={labelText}
151
+ onSubmit={searchBarSubmit}
152
+ textInputProps={textInputProps}
153
+ />
154
+ );
155
+ const input = screen.getByLabelText(textInputProps.labelText);
156
+ expect(textInputProps.onChange).toHaveBeenCalledTimes(0);
157
+
158
+ userEvent.type(input, "search!");
159
+
160
+ // Seven times for every letter in the search string
161
+ expect(textInputProps.onChange).toHaveBeenCalledTimes(7);
162
+ });
163
+
164
+ it("calls the Select onChange callback function", () => {
165
+ selectProps.onChange = jest.fn();
166
+
167
+ render(
168
+ <SearchBar
169
+ helperText={helperText}
170
+ id="id"
171
+ labelText={labelText}
172
+ onSubmit={searchBarSubmit}
173
+ selectProps={selectProps}
174
+ textInputProps={textInputProps}
175
+ />
176
+ );
177
+ const select = screen.getByLabelText(selectProps.labelText);
178
+ expect(selectProps.onChange).toHaveBeenCalledTimes(0);
179
+
180
+ userEvent.selectOptions(select, "Flowers");
181
+ expect(selectProps.onChange).toHaveBeenCalledTimes(1);
182
+
183
+ userEvent.selectOptions(select, "Furniture");
184
+ expect(selectProps.onChange).toHaveBeenCalledTimes(2);
185
+ });
186
+
187
+ it("calls the callback function for the Button component ", () => {
188
+ render(
189
+ <SearchBar
190
+ buttonOnClick={buttonCallback}
191
+ helperText={helperText}
192
+ id="id"
193
+ labelText={labelText}
194
+ onSubmit={searchBarSubmit}
195
+ selectProps={selectProps}
196
+ textInputProps={textInputProps}
197
+ />
198
+ );
199
+ expect(buttonCallback).toHaveBeenCalledTimes(0);
200
+ userEvent.click(screen.getByRole("button"));
201
+ expect(buttonCallback).toHaveBeenCalledTimes(1);
202
+ });
203
+
124
204
  it("calls the callback function on submit ", () => {
125
205
  render(
126
206
  <SearchBar
127
207
  helperText={helperText}
128
208
  id="id"
129
- labelText="searchBar"
209
+ labelText={labelText}
130
210
  onSubmit={searchBarSubmit}
131
211
  selectProps={selectProps}
132
212
  textInputProps={textInputProps}
133
213
  />
134
214
  );
135
215
  expect(searchBarSubmit).toHaveBeenCalledTimes(0);
136
- expect(buttonCallback).toHaveBeenCalledTimes(0);
137
216
  userEvent.click(screen.getByRole("button"));
138
217
  expect(searchBarSubmit).toHaveBeenCalledTimes(1);
139
- expect(buttonCallback).toHaveBeenCalledTimes(1);
140
218
  });
141
219
 
142
- it("Renders 'required' in the placeholder text", () => {
220
+ it("renders a default placeholder", () => {
221
+ const textInputProps: TextInputProps = {
222
+ labelText: "Item Search",
223
+ name: "textInputName",
224
+ };
225
+
226
+ render(
227
+ <SearchBar
228
+ id="requiredState"
229
+ isDisabled
230
+ labelText={labelText}
231
+ onSubmit={jest.fn()}
232
+ textInputProps={textInputProps}
233
+ />
234
+ );
235
+
236
+ expect(screen.getByPlaceholderText("Search terms")).toBeInTheDocument();
237
+ });
238
+
239
+ it("renders 'required' in the placeholder text", () => {
143
240
  const { rerender } = render(
144
241
  <SearchBar
145
242
  id="requiredState"
146
243
  isDisabled
147
- isRequired
148
- labelText="searchbar"
244
+ labelText={labelText}
149
245
  onSubmit={jest.fn()}
150
246
  textInputProps={textInputProps}
151
247
  />
152
248
  );
153
249
 
154
250
  expect(
155
- screen.getByPlaceholderText("Item Search (Required)")
251
+ screen.queryByPlaceholderText("Item Search (Required)")
156
252
  ).not.toBeInTheDocument();
157
253
 
158
254
  rerender(
@@ -160,7 +256,7 @@ describe("SearchBar", () => {
160
256
  id="requiredState"
161
257
  isDisabled
162
258
  isRequired
163
- labelText="searchbar"
259
+ labelText={labelText}
164
260
  onSubmit={jest.fn()}
165
261
  textInputProps={textInputProps}
166
262
  />
@@ -170,13 +266,13 @@ describe("SearchBar", () => {
170
266
  ).toBeInTheDocument();
171
267
  });
172
268
 
173
- it("Renders the UI snapshot correctly", () => {
269
+ it("renders the UI snapshot correctly", () => {
174
270
  const basic = renderer
175
271
  .create(
176
272
  <SearchBar
177
273
  helperText={helperText}
178
274
  id="basic"
179
- labelText="searchbar"
275
+ labelText={labelText}
180
276
  onSubmit={jest.fn()}
181
277
  textInputProps={textInputProps}
182
278
  />
@@ -187,7 +283,7 @@ describe("SearchBar", () => {
187
283
  <SearchBar
188
284
  helperText={helperText}
189
285
  id="withSelect"
190
- labelText="searchbar"
286
+ labelText={labelText}
191
287
  onSubmit={jest.fn()}
192
288
  selectProps={selectProps}
193
289
  textInputProps={textInputProps}
@@ -198,7 +294,7 @@ describe("SearchBar", () => {
198
294
  .create(
199
295
  <SearchBar
200
296
  id="withoutHelperText"
201
- labelText="searchbar"
297
+ labelText={labelText}
202
298
  onSubmit={jest.fn()}
203
299
  textInputProps={textInputProps}
204
300
  />
@@ -209,7 +305,7 @@ describe("SearchBar", () => {
209
305
  <SearchBar
210
306
  id="invalidState"
211
307
  isInvalid
212
- labelText="searchbar"
308
+ labelText={labelText}
213
309
  onSubmit={jest.fn()}
214
310
  textInputProps={textInputProps}
215
311
  />
@@ -220,7 +316,7 @@ describe("SearchBar", () => {
220
316
  <SearchBar
221
317
  id="disabledState"
222
318
  isDisabled
223
- labelText="searchbar"
319
+ labelText={labelText}
224
320
  onSubmit={jest.fn()}
225
321
  textInputProps={textInputProps}
226
322
  />
@@ -232,7 +328,7 @@ describe("SearchBar", () => {
232
328
  id="requiredState"
233
329
  isDisabled
234
330
  isRequired
235
- labelText="searchbar"
331
+ labelText={labelText}
236
332
  onSubmit={jest.fn()}
237
333
  textInputProps={textInputProps}
238
334
  />
@@ -244,7 +340,7 @@ describe("SearchBar", () => {
244
340
  id="noBrandButtonType"
245
341
  isDisabled
246
342
  isRequired
247
- labelText="searchbar"
343
+ labelText={labelText}
248
344
  noBrandButtonType={true}
249
345
  onSubmit={jest.fn()}
250
346
  textInputProps={textInputProps}
@@ -255,7 +351,7 @@ describe("SearchBar", () => {
255
351
  .create(
256
352
  <SearchBar
257
353
  id="withHeading"
258
- labelText="searchbar"
354
+ labelText={labelText}
259
355
  onSubmit={jest.fn()}
260
356
  headingText="A Heading"
261
357
  />
@@ -265,7 +361,7 @@ describe("SearchBar", () => {
265
361
  .create(
266
362
  <SearchBar
267
363
  id="withDescription"
268
- labelText="searchbar"
364
+ labelText={labelText}
269
365
  onSubmit={jest.fn()}
270
366
  descriptionText="A description"
271
367
  />
@@ -275,7 +371,7 @@ describe("SearchBar", () => {
275
371
  .create(
276
372
  <SearchBar
277
373
  id="withHeadingAndDescription"
278
- labelText="searchbar"
374
+ labelText={labelText}
279
375
  onSubmit={jest.fn()}
280
376
  headingText="A Heading"
281
377
  descriptionText="A description"