@patternfly/react-core 4.264.1 → 4.265.0

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 (77) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/esm/components/Badge/Badge.d.ts +2 -0
  3. package/dist/esm/components/Badge/Badge.d.ts.map +1 -1
  4. package/dist/esm/components/Badge/Badge.js +4 -2
  5. package/dist/esm/components/Badge/Badge.js.map +1 -1
  6. package/dist/esm/components/TimePicker/TimePicker.d.ts +0 -1
  7. package/dist/esm/components/TimePicker/TimePicker.d.ts.map +1 -1
  8. package/dist/esm/components/TimePicker/TimePicker.js +1 -9
  9. package/dist/esm/components/TimePicker/TimePicker.js.map +1 -1
  10. package/dist/esm/next/components/Dropdown/DropdownItem.d.ts +2 -0
  11. package/dist/esm/next/components/Dropdown/DropdownItem.d.ts.map +1 -1
  12. package/dist/esm/next/components/Dropdown/DropdownItem.js +2 -2
  13. package/dist/esm/next/components/Dropdown/DropdownItem.js.map +1 -1
  14. package/dist/esm/next/components/Wizard/Wizard.d.ts +1 -1
  15. package/dist/esm/next/components/Wizard/Wizard.d.ts.map +1 -1
  16. package/dist/esm/next/components/Wizard/WizardContext.d.ts +2 -2
  17. package/dist/esm/next/components/Wizard/WizardContext.d.ts.map +1 -1
  18. package/dist/esm/next/components/Wizard/WizardFooter.d.ts +2 -2
  19. package/dist/esm/next/components/Wizard/WizardFooter.d.ts.map +1 -1
  20. package/dist/esm/next/components/Wizard/WizardNavInternal.js +2 -2
  21. package/dist/esm/next/components/Wizard/WizardNavInternal.js.map +1 -1
  22. package/dist/esm/next/components/Wizard/WizardNavItem.js +1 -1
  23. package/dist/esm/next/components/Wizard/WizardNavItem.js.map +1 -1
  24. package/dist/esm/next/components/Wizard/WizardStep.d.ts +2 -0
  25. package/dist/esm/next/components/Wizard/WizardStep.d.ts.map +1 -1
  26. package/dist/esm/next/components/Wizard/WizardStep.js.map +1 -1
  27. package/dist/esm/next/components/Wizard/types.d.ts +4 -2
  28. package/dist/esm/next/components/Wizard/types.d.ts.map +1 -1
  29. package/dist/esm/next/components/Wizard/types.js.map +1 -1
  30. package/dist/js/components/Badge/Badge.d.ts +2 -0
  31. package/dist/js/components/Badge/Badge.d.ts.map +1 -1
  32. package/dist/js/components/Badge/Badge.js +4 -2
  33. package/dist/js/components/Badge/Badge.js.map +1 -1
  34. package/dist/js/components/TimePicker/TimePicker.d.ts +0 -1
  35. package/dist/js/components/TimePicker/TimePicker.d.ts.map +1 -1
  36. package/dist/js/components/TimePicker/TimePicker.js +1 -9
  37. package/dist/js/components/TimePicker/TimePicker.js.map +1 -1
  38. package/dist/js/next/components/Dropdown/DropdownItem.d.ts +2 -0
  39. package/dist/js/next/components/Dropdown/DropdownItem.d.ts.map +1 -1
  40. package/dist/js/next/components/Dropdown/DropdownItem.js +2 -2
  41. package/dist/js/next/components/Dropdown/DropdownItem.js.map +1 -1
  42. package/dist/js/next/components/Wizard/Wizard.d.ts +1 -1
  43. package/dist/js/next/components/Wizard/Wizard.d.ts.map +1 -1
  44. package/dist/js/next/components/Wizard/WizardContext.d.ts +2 -2
  45. package/dist/js/next/components/Wizard/WizardContext.d.ts.map +1 -1
  46. package/dist/js/next/components/Wizard/WizardFooter.d.ts +2 -2
  47. package/dist/js/next/components/Wizard/WizardFooter.d.ts.map +1 -1
  48. package/dist/js/next/components/Wizard/WizardNavInternal.js +2 -2
  49. package/dist/js/next/components/Wizard/WizardNavInternal.js.map +1 -1
  50. package/dist/js/next/components/Wizard/WizardNavItem.js +1 -1
  51. package/dist/js/next/components/Wizard/WizardNavItem.js.map +1 -1
  52. package/dist/js/next/components/Wizard/WizardStep.d.ts +2 -0
  53. package/dist/js/next/components/Wizard/WizardStep.d.ts.map +1 -1
  54. package/dist/js/next/components/Wizard/WizardStep.js.map +1 -1
  55. package/dist/js/next/components/Wizard/types.d.ts +4 -2
  56. package/dist/js/next/components/Wizard/types.d.ts.map +1 -1
  57. package/dist/js/next/components/Wizard/types.js.map +1 -1
  58. package/dist/umd/react-core.min.css +233 -233
  59. package/dist/umd/react-core.min.js +2 -2
  60. package/package.json +6 -6
  61. package/src/components/Badge/Badge.tsx +4 -0
  62. package/src/components/Badge/__tests__/Badge.test.tsx +10 -0
  63. package/src/components/Badge/examples/BadgeUnread.tsx +12 -1
  64. package/src/components/Menu/examples/MenuWithDrilldownBreadcrumbs.tsx +60 -22
  65. package/src/components/TimePicker/TimePicker.tsx +0 -11
  66. package/src/next/components/Dropdown/DropdownItem.tsx +4 -1
  67. package/src/next/components/Wizard/Wizard.tsx +1 -1
  68. package/src/next/components/Wizard/WizardContext.tsx +2 -2
  69. package/src/next/components/Wizard/WizardFooter.tsx +2 -2
  70. package/src/next/components/Wizard/WizardNavInternal.tsx +1 -1
  71. package/src/next/components/Wizard/WizardNavItem.tsx +1 -1
  72. package/src/next/components/Wizard/WizardStep.tsx +2 -0
  73. package/src/next/components/Wizard/__tests__/Wizard.test.tsx +33 -1
  74. package/src/next/components/Wizard/__tests__/WizardStep.test.tsx +1 -2
  75. package/src/next/components/Wizard/examples/Wizard.md +1 -1
  76. package/src/next/components/Wizard/examples/WizardKitchenSink.tsx +21 -2
  77. package/src/next/components/Wizard/types.tsx +9 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patternfly/react-core",
3
- "version": "4.264.1",
3
+ "version": "4.265.0",
4
4
  "description": "This library provides a set of common React components for use with the PatternFly reference implementation.",
5
5
  "main": "dist/js/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -51,16 +51,16 @@
51
51
  "generate": "node scripts/copyStyles.js"
52
52
  },
53
53
  "dependencies": {
54
- "@patternfly/react-icons": "^4.93.0",
55
- "@patternfly/react-styles": "^4.92.0",
56
- "@patternfly/react-tokens": "^4.94.0",
54
+ "@patternfly/react-icons": "^4.93.1",
55
+ "@patternfly/react-styles": "^4.92.1",
56
+ "@patternfly/react-tokens": "^4.94.1",
57
57
  "focus-trap": "6.9.2",
58
58
  "react-dropzone": "9.0.0",
59
59
  "tippy.js": "5.1.2",
60
60
  "tslib": "^2.0.0"
61
61
  },
62
62
  "devDependencies": {
63
- "@patternfly/patternfly": "4.221.2",
63
+ "@patternfly/patternfly": "4.221.3",
64
64
  "@rollup/plugin-commonjs": "^21.0.0",
65
65
  "@rollup/plugin-node-resolve": "^15.0.1",
66
66
  "@rollup/plugin-replace": "^3.0.0",
@@ -77,5 +77,5 @@
77
77
  "react": "^16.8 || ^17 || ^18",
78
78
  "react-dom": "^16.8 || ^17 || ^18"
79
79
  },
80
- "gitHead": "3c9dd17f7327ffafa0b9751074b188ea19eaeee6"
80
+ "gitHead": "47c6127c70191349261aec122b56e6ca61fa0c99"
81
81
  }
@@ -3,6 +3,8 @@ import { css } from '@patternfly/react-styles';
3
3
  import styles from '@patternfly/react-styles/css/components/Badge/badge';
4
4
 
5
5
  export interface BadgeProps extends React.HTMLProps<HTMLSpanElement> {
6
+ /** Text announced by screen readers to indicate the current content/status of the badge. */
7
+ screenReaderText?: string;
6
8
  /** Adds styling to the badge to indicate it has been read */
7
9
  isRead?: boolean;
8
10
  /** content rendered inside the Badge */
@@ -15,6 +17,7 @@ export const Badge: React.FunctionComponent<BadgeProps> = ({
15
17
  isRead = false,
16
18
  className = '',
17
19
  children = '',
20
+ screenReaderText,
18
21
  ...props
19
22
  }: BadgeProps) => (
20
23
  <span
@@ -22,6 +25,7 @@ export const Badge: React.FunctionComponent<BadgeProps> = ({
22
25
  className={css(styles.badge, (isRead ? styles.modifiers.read : styles.modifiers.unread) as any, className)}
23
26
  >
24
27
  {children}
28
+ {screenReaderText && <span className="pf-screen-reader">{screenReaderText}</span>}
25
29
  </span>
26
30
  );
27
31
  Badge.displayName = 'Badge';
@@ -31,6 +31,16 @@ test('Renders with class name pf-m-read when isRead prop is true', () => {
31
31
  expect(screen.getByText('Test')).toHaveClass('pf-m-read');
32
32
  });
33
33
 
34
+ test('Does not render pf-screen-reader class by default', () => {
35
+ render(<Badge>Test</Badge>);
36
+ expect(screen.getByText('Test')).not.toContainHTML('<span class="pf-screen-reader"></span>');
37
+ });
38
+
39
+ test('Renders screenReaderText passed via prop', () => {
40
+ render(<Badge screenReaderText="Custom screen reader text">Test</Badge>);
41
+ expect(screen.getByText('Custom screen reader text')).toBeInTheDocument();
42
+ });
43
+
34
44
  test('Renders with custom class name when className prop is provided', () => {
35
45
  render(<Badge className="custom-class">Test</Badge>);
36
46
  expect(screen.getByText('Test')).toHaveClass('custom-class');
@@ -3,6 +3,17 @@ import { Badge } from '@patternfly/react-core';
3
3
 
4
4
  export const BadgeUnread: React.FunctionComponent = () => (
5
5
  <React.Fragment>
6
- <Badge key={1}>7</Badge> <Badge key={2}>24</Badge> <Badge key={3}>240</Badge> <Badge key={4}>999+</Badge>
6
+ <Badge key={1} screenReaderText="Unread Messages">
7
+ 7
8
+ </Badge>
9
+ <Badge key={2} screenReaderText="Unread Messages">
10
+ 24
11
+ </Badge>
12
+ <Badge key={3} screenReaderText="Unread Messages">
13
+ 240
14
+ </Badge>
15
+ <Badge key={4} screenReaderText="Unread Messages">
16
+ 999+
17
+ </Badge>
7
18
  </React.Fragment>
8
19
  );
@@ -26,7 +26,7 @@ export const MenuWithDrilldownBreadcrumbs: React.FunctionComponent = () => {
26
26
  const [drilldownPath, setDrilldownPath] = React.useState<string[]>([]);
27
27
  const [menuHeights, setMenuHeights] = React.useState<any>({});
28
28
  const [activeMenu, setActiveMenu] = React.useState<string>('breadcrumbs-rootMenu');
29
- const [breadcrumb, setBreadcrumb] = React.useState<JSX.Element>();
29
+ const [breadcrumb, setBreadcrumb] = React.useState<JSX.Element | null>();
30
30
  const [withMaxMenuHeight, setWithMaxMenuHeight] = React.useState(false);
31
31
 
32
32
  const onToggle = (isOpen: boolean, key: string) => {
@@ -37,6 +37,12 @@ export const MenuWithDrilldownBreadcrumbs: React.FunctionComponent = () => {
37
37
  case 'label':
38
38
  setBreadcrumb(labelsBreadcrumb(isOpen));
39
39
  break;
40
+ case 'pause-app':
41
+ setBreadcrumb(pauseRolloutsAppGrpBreadcrumb(isOpen));
42
+ break;
43
+ case 'pause-label':
44
+ setBreadcrumb(pauseRolloutsLabelsBreadcrumb(isOpen));
45
+ break;
40
46
  default:
41
47
  break;
42
48
  }
@@ -46,14 +52,17 @@ export const MenuWithDrilldownBreadcrumbs: React.FunctionComponent = () => {
46
52
  setWithMaxMenuHeight(checked);
47
53
  };
48
54
 
49
- const drillOut = (toMenuId: string, fromPathId: string, _breadcrumb: JSX.Element | null) => {
50
- const indexOfMenuId = menuDrilledIn.indexOf(toMenuId);
51
- const menuDrilledInSansLast = menuDrilledIn.slice(0, indexOfMenuId);
52
- const indexOfMenuIdPath = drilldownPath.indexOf(fromPathId);
53
- const pathSansLast = drilldownPath.slice(0, indexOfMenuIdPath);
54
- setMenuDrilledIn(menuDrilledInSansLast);
55
- setDrilldownPath(pathSansLast);
55
+ const drillOut = (toMenuId: string, fromPathId: string, breadcrumb: JSX.Element | null) => {
56
+ setMenuDrilledIn(prevMenuDrilledIn => {
57
+ const indexOfMenuId = prevMenuDrilledIn.indexOf(toMenuId);
58
+ return prevMenuDrilledIn.slice(0, indexOfMenuId);
59
+ });
60
+ setDrilldownPath(prevDrilldownPath => {
61
+ const indexOfMenuIdPath = prevDrilldownPath.indexOf(fromPathId);
62
+ return prevDrilldownPath.slice(0, indexOfMenuIdPath);
63
+ });
56
64
  setActiveMenu(toMenuId);
65
+ setBreadcrumb(breadcrumb);
57
66
  };
58
67
 
59
68
  const setHeight = (menuId: string, height: number) => {
@@ -146,31 +155,59 @@ export const MenuWithDrilldownBreadcrumbs: React.FunctionComponent = () => {
146
155
  </Breadcrumb>
147
156
  );
148
157
 
149
- const pauseRolloutsAppGrpBreadcrumb = (
158
+ const pauseRolloutsAppGrpBreadcrumb = (isOpen: boolean) => (
150
159
  <Breadcrumb>
151
160
  <BreadcrumbItem component="button" onClick={() => drillOut('breadcrumbs-rootMenu', 'group:pause_rollout', null)}>
152
161
  Root
153
162
  </BreadcrumbItem>
154
- <BreadcrumbItem
155
- component="button"
156
- onClick={() => drillOut('breadcrumbs-drilldownMenuPause', 'group:app_grouping', pauseRolloutsBreadcrumb)}
157
- >
158
- Pause rollouts
163
+ <BreadcrumbItem isDropdown>
164
+ <Dropdown
165
+ toggle={
166
+ <BadgeToggle id="toggle-id" onToggle={open => onToggle(open, 'pause-app')}>
167
+ 1
168
+ </BadgeToggle>
169
+ }
170
+ isOpen={isOpen}
171
+ dropdownItems={[
172
+ <DropdownItem
173
+ key="dropdown-pause"
174
+ component="button"
175
+ icon={<AngleLeftIcon />}
176
+ onClick={() => drillOut('breadcrumbs-drilldownMenuPause', 'group:app_grouping', pauseRolloutsBreadcrumb)}
177
+ >
178
+ Pause rollouts
179
+ </DropdownItem>
180
+ ]}
181
+ />
159
182
  </BreadcrumbItem>
160
183
  <BreadcrumbHeading component="button">Application Grouping</BreadcrumbHeading>
161
184
  </Breadcrumb>
162
185
  );
163
186
 
164
- const pauseRolloutsLabelsBreadcrumb = (
187
+ const pauseRolloutsLabelsBreadcrumb = (isOpen: boolean) => (
165
188
  <Breadcrumb>
166
189
  <BreadcrumbItem component="button" onClick={() => drillOut('breadcrumbs-rootMenu', 'group:pause_rollout', null)}>
167
190
  Root
168
191
  </BreadcrumbItem>
169
- <BreadcrumbItem
170
- component="button"
171
- onClick={() => drillOut('breadcrumbs-drilldownMenuPause', 'group:labels', pauseRolloutsBreadcrumb)}
172
- >
173
- Pause rollouts
192
+ <BreadcrumbItem isDropdown>
193
+ <Dropdown
194
+ toggle={
195
+ <BadgeToggle id="toggle-id" onToggle={open => onToggle(open, 'pause-label')}>
196
+ 1
197
+ </BadgeToggle>
198
+ }
199
+ isOpen={isOpen}
200
+ dropdownItems={[
201
+ <DropdownItem
202
+ key="dropdown-pause"
203
+ component="button"
204
+ icon={<AngleLeftIcon />}
205
+ onClick={() => drillOut('breadcrumbs-drilldownMenuPause', 'group:labels', pauseRolloutsBreadcrumb)}
206
+ >
207
+ Pause rollouts
208
+ </DropdownItem>
209
+ ]}
210
+ />
174
211
  </BreadcrumbItem>
175
212
  <BreadcrumbHeading component="button">Labels</BreadcrumbHeading>
176
213
  </Breadcrumb>
@@ -205,6 +242,7 @@ export const MenuWithDrilldownBreadcrumbs: React.FunctionComponent = () => {
205
242
  onDrillIn={drillIn}
206
243
  onDrillOut={() => drillOut}
207
244
  onGetMenuHeight={setHeight}
245
+ isScrollable={withMaxMenuHeight}
208
246
  >
209
247
  {breadcrumb && (
210
248
  <>
@@ -270,7 +308,7 @@ export const MenuWithDrilldownBreadcrumbs: React.FunctionComponent = () => {
270
308
  itemId="group:app_grouping"
271
309
  description="Groups A-C"
272
310
  direction="down"
273
- onClick={() => setBreadcrumb(pauseRolloutsAppGrpBreadcrumb)}
311
+ onClick={() => setBreadcrumb(pauseRolloutsAppGrpBreadcrumb(false))}
274
312
  drilldownMenu={
275
313
  <DrilldownMenu id="breadcrumbs-drilldownMenuGrouping">
276
314
  <MenuItem itemId="group_a">Group A</MenuItem>
@@ -285,7 +323,7 @@ export const MenuWithDrilldownBreadcrumbs: React.FunctionComponent = () => {
285
323
  <MenuItem
286
324
  itemId="group:labels"
287
325
  direction="down"
288
- onClick={() => setBreadcrumb(pauseRolloutsLabelsBreadcrumb)}
326
+ onClick={() => setBreadcrumb(pauseRolloutsLabelsBreadcrumb(false))}
289
327
  drilldownMenu={
290
328
  <DrilldownMenu id="breadcrumbs-drilldownMenuLabels">
291
329
  <MenuItem itemId="label_1">Label 1</MenuItem>
@@ -426,16 +426,6 @@ export class TimePicker extends React.Component<TimePickerProps, TimePickerState
426
426
  });
427
427
  };
428
428
 
429
- onBlur = (event: React.FocusEvent<HTMLInputElement>) => {
430
- const { timeRegex } = this.state;
431
- const { delimiter, is24Hour, includeSeconds } = this.props;
432
- const time = parseTime(event.currentTarget.value, timeRegex, delimiter, !is24Hour, includeSeconds);
433
-
434
- this.setState({
435
- isInvalid: !this.isValid(time)
436
- });
437
- };
438
-
439
429
  render() {
440
430
  const {
441
431
  'aria-label': ariaLabel,
@@ -507,7 +497,6 @@ export class TimePicker extends React.Component<TimePickerProps, TimePickerState
507
497
  iconVariant="clock"
508
498
  onClick={this.onInputClick}
509
499
  onChange={this.onInputChange}
510
- onBlur={this.onBlur}
511
500
  autoComplete="off"
512
501
  isDisabled={isDisabled}
513
502
  ref={this.inputRef}
@@ -10,6 +10,8 @@ export interface DropdownItemProps extends Omit<MenuItemProps, 'ref'>, OUIAProps
10
10
  className?: string;
11
11
  /** Description of the dropdown item */
12
12
  description?: React.ReactNode;
13
+ /** Identifies the component in the dropdown onSelect callback */
14
+ itemId?: any;
13
15
  /** Value to overwrite the randomly generated data-ouia-component-id.*/
14
16
  ouiaId?: number | string;
15
17
  /** Set the value of data-ouia-safe. Only set to true when the component is in a static state, i.e. no animations are occurring. At all other times, this value must be false. */
@@ -20,13 +22,14 @@ export const DropdownItem: React.FunctionComponent<MenuItemProps> = ({
20
22
  children,
21
23
  className,
22
24
  description,
25
+ itemId,
23
26
  ouiaId,
24
27
  ouiaSafe,
25
28
  ...props
26
29
  }: DropdownItemProps) => {
27
30
  const ouiaProps = useOUIAProps(DropdownItem.displayName, ouiaId, ouiaSafe);
28
31
  return (
29
- <MenuItem className={css(className)} description={description} {...ouiaProps} {...props}>
32
+ <MenuItem className={css(className)} description={description} itemId={itemId} {...ouiaProps} {...props}>
30
33
  {children}
31
34
  </MenuItem>
32
35
  );
@@ -49,7 +49,7 @@ export interface WizardProps extends React.HTMLProps<HTMLDivElement> {
49
49
  /** Callback function after back button is clicked */
50
50
  onBack?: WizardNavStepFunction;
51
51
  /** Callback function to save at the end of the wizard, if not specified uses onClose */
52
- onSave?: () => void;
52
+ onSave?: () => void | Promise<void>;
53
53
  /** Callback function to close the wizard */
54
54
  onClose?: () => void;
55
55
  }
@@ -12,9 +12,9 @@ export interface WizardContextProps {
12
12
  /** Footer element */
13
13
  footer: React.ReactElement;
14
14
  /** Navigate to the next step */
15
- onNext: () => void;
15
+ onNext: () => void | Promise<void>;
16
16
  /** Navigate to the previous step */
17
- onBack: () => void;
17
+ onBack: () => void | Promise<void>;
18
18
  /** Close the wizard */
19
19
  onClose: () => void;
20
20
  /** Navigate to step by ID */
@@ -14,9 +14,9 @@ export interface WizardFooterProps {
14
14
  /** The active step */
15
15
  activeStep: WizardControlStep;
16
16
  /** Next button callback */
17
- onNext: () => WizardNavStepFunction | void;
17
+ onNext: () => WizardNavStepFunction | void | Promise<void>;
18
18
  /** Back button callback */
19
- onBack: () => WizardNavStepFunction | void;
19
+ onBack: () => WizardNavStepFunction | void | Promise<void>;
20
20
  /** Cancel link callback */
21
21
  onClose: () => void;
22
22
  /** Custom text for the Next button. The current step's nextButtonText takes precedence. */
@@ -97,7 +97,7 @@ export const WizardNavInternal = ({ nav, isStepVisitRequired, isNavExpanded }: W
97
97
  key={step.id}
98
98
  id={step.id}
99
99
  content={step.name}
100
- isExpandable={true}
100
+ isExpandable={step.isCollapsible ?? true}
101
101
  isCurrent={hasActiveChild}
102
102
  isDisabled={!hasEnabledChildren}
103
103
  isVisited={step.isVisited}
@@ -109,7 +109,7 @@ export const WizardNavItem: React.FunctionComponent<WizardNavItemProps> = ({
109
109
  <span className={css(styles.wizardNavLinkText)}>{content}</span>
110
110
  <span className={css(styles.wizardNavLinkToggle)}>
111
111
  <span className={css(styles.wizardNavLinkToggleIcon)}>
112
- <AngleRightIcon />
112
+ <AngleRightIcon aria-label={`${isCurrent ? 'Collapse' : 'Expand'} step icon`} />
113
113
  </span>
114
114
  </span>
115
115
  </>
@@ -30,6 +30,8 @@ export interface WizardStepProps {
30
30
  footer?: React.ReactElement | Partial<WizardFooterProps>;
31
31
  /** Used to determine icon next to the step's navigation item */
32
32
  status?: 'default' | 'error';
33
+ /** Flag to determine whether sub-steps can collapse or not */
34
+ isCollapsible?: boolean;
33
35
  }
34
36
 
35
37
  export const WizardStep = ({ children, steps: _subSteps, ...props }: WizardStepProps) => {
@@ -278,7 +278,7 @@ test('calls onClose on cancel link click', async () => {
278
278
  expect(onClose).toHaveBeenCalled();
279
279
  });
280
280
 
281
- test('unmounts inactive steps by default', async () => {
281
+ test('does not render inactive step content', async () => {
282
282
  const user = userEvent.setup();
283
283
 
284
284
  render(
@@ -297,3 +297,35 @@ test('unmounts inactive steps by default', async () => {
297
297
  expect(screen.queryByText('Step 1 content')).toBeNull();
298
298
  expect(screen.getByText('Step 2 content')).toBeVisible();
299
299
  });
300
+
301
+ test('parent steps have collapsed sub-steps by default unless the step is active', async () => {
302
+ const user = userEvent.setup();
303
+
304
+ render(
305
+ <Wizard startIndex={2}>
306
+ <WizardStep id="step-1" name="Test step 1" />
307
+ <WizardStep id="step-2" name="Test step 2" steps={[<WizardStep id="sub-step-1" name="Test sub step 1" />]} />
308
+ </Wizard>
309
+ );
310
+
311
+ expect(screen.getByLabelText('Expand step icon')).toBeVisible();
312
+
313
+ await user.click(screen.getByRole('button', { name: 'Next' }));
314
+
315
+ expect(screen.getByLabelText('Collapse step icon')).toBeVisible();
316
+ });
317
+
318
+ test('parent step can be non-collapsible by setting isCollapsible to false', () => {
319
+ render(
320
+ <Wizard>
321
+ <WizardStep
322
+ id="step-1"
323
+ name="Test step 1"
324
+ isCollapsible={false}
325
+ steps={[<WizardStep id="sub-step-1" name="Sub step 1" />]}
326
+ />
327
+ </Wizard>
328
+ );
329
+
330
+ expect(screen.queryByLabelText('step icon', { exact: false })).toBeNull();
331
+ });
@@ -31,8 +31,7 @@ const wizardContext: WizardContext.WizardContextProps = {
31
31
  goToStepByName: jest.fn(),
32
32
  goToStepByIndex: jest.fn(),
33
33
  setFooter: jest.fn(),
34
- getStep: jest.fn(),
35
- setSteps: jest.fn()
34
+ getStep: jest.fn()
36
35
  };
37
36
 
38
37
  const useWizardContextSpy = jest.spyOn(WizardContext, 'useWizardContext');
@@ -96,7 +96,7 @@ Custom operations when navigating between steps can be achieved by utilizing `on
96
96
 
97
97
  ```noLive
98
98
  /** Callback for the Wizard's 'onNext', 'onBack', and 'onNavByIndex' properties */
99
- type WizardNavStepFunction = (currentStep: WizardNavStepData, previousStep: WizardNavStepData) => void;
99
+ type WizardNavStepFunction = (currentStep: WizardNavStepData, previousStep: WizardNavStepData) => void | Promise<void>;
100
100
 
101
101
  /** Data returned for either parameter of WizardNavStepFunction */
102
102
  type WizardNavStepData = Pick<WizardControlStep, 'id' | 'name'>;
@@ -161,6 +161,16 @@ const StepContentWithActions = () => {
161
161
 
162
162
  export const WizardKitchenSink: React.FunctionComponent = () => {
163
163
  const onNext: WizardNavStepFunction = (_currentStep: WizardNavStepData, _previousStep: WizardNavStepData) => {};
164
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
165
+
166
+ async function onSubmit(): Promise<void> {
167
+ setIsSubmitting(true);
168
+
169
+ await new Promise(resolve => setTimeout(resolve, 5000));
170
+
171
+ setIsSubmitting(false);
172
+ alert('50 points to Gryffindor!');
173
+ }
164
174
 
165
175
  return (
166
176
  <SomeContextProvider>
@@ -207,8 +217,17 @@ export const WizardKitchenSink: React.FunctionComponent = () => {
207
217
  >
208
218
  Step 3 content w/ custom async footer
209
219
  </WizardStep>
210
- <WizardStep id={StepId.ReviewStep} name="Review" footer={{ nextButtonText: 'Submit' }}>
211
- Review step content
220
+ <WizardStep
221
+ id={StepId.ReviewStep}
222
+ name="Review"
223
+ footer={{
224
+ nextButtonText: 'Submit',
225
+ onNext: onSubmit,
226
+ isNextDisabled: isSubmitting,
227
+ isBackDisabled: isSubmitting
228
+ }}
229
+ >
230
+ {isSubmitting ? 'Calculating wizard score...' : 'Review step content'}
212
231
  </WizardStep>
213
232
  </Wizard>
214
233
  )}
@@ -34,6 +34,8 @@ export enum WizardNavItemStatus {
34
34
  export interface WizardParentStep extends WizardBasicStep {
35
35
  /** Nested step IDs */
36
36
  subStepIds: (string | number)[];
37
+ /** Flag to determine whether sub-steps can collapse or not */
38
+ isCollapsible?: boolean;
37
39
  }
38
40
 
39
41
  /** Type used to define sub-steps. */
@@ -46,7 +48,10 @@ export interface WizardSubStep extends WizardBasicStep {
46
48
  export type WizardControlStep = WizardBasicStep | WizardParentStep | WizardSubStep;
47
49
 
48
50
  /** Callback for the Wizard's 'onNext', 'onBack', and 'onNavByIndex' properties. */
49
- export type WizardNavStepFunction = (currentStep: WizardNavStepData, previousStep: WizardNavStepData) => void;
51
+ export type WizardNavStepFunction = (
52
+ currentStep: WizardNavStepData,
53
+ previousStep: WizardNavStepData
54
+ ) => void | Promise<void>;
50
55
 
51
56
  /** Data returned for either parameter of WizardNavStepFunction. */
52
57
  export interface WizardNavStepData {
@@ -81,9 +86,9 @@ export type CustomWizardNavItemFunction = (
81
86
  /** Callback for the Wizard's 'footer' property. Returns element which replaces the Wizard's default footer. */
82
87
  export type CustomWizardFooterFunction = (
83
88
  activeStep: WizardControlStep,
84
- onNext: () => void,
85
- onBack: () => void,
86
- onClose: () => void
89
+ onNext: () => void | Promise<void>,
90
+ onBack: () => void | Promise<void>,
91
+ onClose: () => void | Promise<void>
87
92
  ) => React.ReactElement<WizardFooterProps>;
88
93
 
89
94
  export function isCustomWizardNav(nav: WizardNavType): nav is CustomWizardNavFunction | React.ReactElement {