@patternfly/react-core 4.255.1 → 4.255.2

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 (95) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/esm/next/components/Wizard/Wizard.d.ts +1 -3
  3. package/dist/esm/next/components/Wizard/Wizard.d.ts.map +1 -1
  4. package/dist/esm/next/components/Wizard/Wizard.js +36 -45
  5. package/dist/esm/next/components/Wizard/Wizard.js.map +1 -1
  6. package/dist/esm/next/components/Wizard/WizardBody.d.ts +2 -2
  7. package/dist/esm/next/components/Wizard/WizardBody.d.ts.map +1 -1
  8. package/dist/esm/next/components/Wizard/WizardBody.js +2 -2
  9. package/dist/esm/next/components/Wizard/WizardBody.js.map +1 -1
  10. package/dist/esm/next/components/Wizard/WizardContext.d.ts +2 -7
  11. package/dist/esm/next/components/Wizard/WizardContext.d.ts.map +1 -1
  12. package/dist/esm/next/components/Wizard/WizardContext.js +18 -39
  13. package/dist/esm/next/components/Wizard/WizardContext.js.map +1 -1
  14. package/dist/esm/next/components/Wizard/WizardFooter.d.ts +3 -3
  15. package/dist/esm/next/components/Wizard/WizardFooter.d.ts.map +1 -1
  16. package/dist/esm/next/components/Wizard/WizardFooter.js +3 -3
  17. package/dist/esm/next/components/Wizard/WizardFooter.js.map +1 -1
  18. package/dist/esm/next/components/Wizard/WizardNavInternal.d.ts.map +1 -1
  19. package/dist/esm/next/components/Wizard/WizardNavInternal.js +12 -12
  20. package/dist/esm/next/components/Wizard/WizardNavInternal.js.map +1 -1
  21. package/dist/esm/next/components/Wizard/WizardStep.d.ts +1 -3
  22. package/dist/esm/next/components/Wizard/WizardStep.d.ts.map +1 -1
  23. package/dist/esm/next/components/Wizard/WizardStep.js +10 -18
  24. package/dist/esm/next/components/Wizard/WizardStep.js.map +1 -1
  25. package/dist/esm/next/components/Wizard/WizardToggle.d.ts +2 -4
  26. package/dist/esm/next/components/Wizard/WizardToggle.d.ts.map +1 -1
  27. package/dist/esm/next/components/Wizard/WizardToggle.js +19 -16
  28. package/dist/esm/next/components/Wizard/WizardToggle.js.map +1 -1
  29. package/dist/esm/next/components/Wizard/hooks/useWizardFooter.js +3 -3
  30. package/dist/esm/next/components/Wizard/hooks/useWizardFooter.js.map +1 -1
  31. package/dist/esm/next/components/Wizard/types.d.ts +5 -3
  32. package/dist/esm/next/components/Wizard/types.d.ts.map +1 -1
  33. package/dist/esm/next/components/Wizard/types.js.map +1 -1
  34. package/dist/esm/next/components/Wizard/utils.d.ts +3 -3
  35. package/dist/esm/next/components/Wizard/utils.d.ts.map +1 -1
  36. package/dist/esm/next/components/Wizard/utils.js +14 -11
  37. package/dist/esm/next/components/Wizard/utils.js.map +1 -1
  38. package/dist/js/next/components/Wizard/Wizard.d.ts +1 -3
  39. package/dist/js/next/components/Wizard/Wizard.d.ts.map +1 -1
  40. package/dist/js/next/components/Wizard/Wizard.js +36 -45
  41. package/dist/js/next/components/Wizard/Wizard.js.map +1 -1
  42. package/dist/js/next/components/Wizard/WizardBody.d.ts +2 -2
  43. package/dist/js/next/components/Wizard/WizardBody.d.ts.map +1 -1
  44. package/dist/js/next/components/Wizard/WizardBody.js +2 -2
  45. package/dist/js/next/components/Wizard/WizardBody.js.map +1 -1
  46. package/dist/js/next/components/Wizard/WizardContext.d.ts +2 -7
  47. package/dist/js/next/components/Wizard/WizardContext.d.ts.map +1 -1
  48. package/dist/js/next/components/Wizard/WizardContext.js +15 -37
  49. package/dist/js/next/components/Wizard/WizardContext.js.map +1 -1
  50. package/dist/js/next/components/Wizard/WizardFooter.d.ts +3 -3
  51. package/dist/js/next/components/Wizard/WizardFooter.d.ts.map +1 -1
  52. package/dist/js/next/components/Wizard/WizardFooter.js +3 -3
  53. package/dist/js/next/components/Wizard/WizardFooter.js.map +1 -1
  54. package/dist/js/next/components/Wizard/WizardNavInternal.d.ts.map +1 -1
  55. package/dist/js/next/components/Wizard/WizardNavInternal.js +12 -12
  56. package/dist/js/next/components/Wizard/WizardNavInternal.js.map +1 -1
  57. package/dist/js/next/components/Wizard/WizardStep.d.ts +1 -3
  58. package/dist/js/next/components/Wizard/WizardStep.d.ts.map +1 -1
  59. package/dist/js/next/components/Wizard/WizardStep.js +9 -18
  60. package/dist/js/next/components/Wizard/WizardStep.js.map +1 -1
  61. package/dist/js/next/components/Wizard/WizardToggle.d.ts +2 -4
  62. package/dist/js/next/components/Wizard/WizardToggle.d.ts.map +1 -1
  63. package/dist/js/next/components/Wizard/WizardToggle.js +18 -16
  64. package/dist/js/next/components/Wizard/WizardToggle.js.map +1 -1
  65. package/dist/js/next/components/Wizard/hooks/useWizardFooter.js +3 -3
  66. package/dist/js/next/components/Wizard/hooks/useWizardFooter.js.map +1 -1
  67. package/dist/js/next/components/Wizard/types.d.ts +5 -3
  68. package/dist/js/next/components/Wizard/types.d.ts.map +1 -1
  69. package/dist/js/next/components/Wizard/types.js.map +1 -1
  70. package/dist/js/next/components/Wizard/utils.d.ts +3 -3
  71. package/dist/js/next/components/Wizard/utils.d.ts.map +1 -1
  72. package/dist/js/next/components/Wizard/utils.js +16 -13
  73. package/dist/js/next/components/Wizard/utils.js.map +1 -1
  74. package/package.json +2 -2
  75. package/src/components/Wizard/examples/Wizard.md +11 -7
  76. package/src/next/components/Wizard/Wizard.tsx +35 -54
  77. package/src/next/components/Wizard/WizardBody.tsx +3 -3
  78. package/src/next/components/Wizard/WizardContext.tsx +29 -61
  79. package/src/next/components/Wizard/WizardFooter.tsx +6 -6
  80. package/src/next/components/Wizard/WizardNavInternal.tsx +18 -17
  81. package/src/next/components/Wizard/WizardStep.tsx +19 -30
  82. package/src/next/components/Wizard/WizardToggle.tsx +22 -24
  83. package/src/next/components/Wizard/__tests__/Wizard.test.tsx +1 -21
  84. package/src/next/components/Wizard/__tests__/WizardBody.test.tsx +2 -2
  85. package/src/next/components/Wizard/__tests__/WizardFooter.test.tsx +5 -5
  86. package/src/next/components/Wizard/__tests__/WizardStep.test.tsx +22 -76
  87. package/src/next/components/Wizard/__tests__/WizardToggle.test.tsx +7 -11
  88. package/src/next/components/Wizard/__tests__/utils.test.tsx +3 -3
  89. package/src/next/components/Wizard/examples/Wizard.md +4 -4
  90. package/src/next/components/Wizard/examples/WizardCustomNav.tsx +4 -4
  91. package/src/next/components/Wizard/examples/WizardKitchenSink.tsx +74 -85
  92. package/src/next/components/Wizard/hooks/__tests__/useWizardFooter.test.tsx +4 -4
  93. package/src/next/components/Wizard/hooks/useWizardFooter.tsx +3 -3
  94. package/src/next/components/Wizard/types.tsx +5 -3
  95. package/src/next/components/Wizard/utils.ts +35 -25
@@ -1,8 +1,7 @@
1
1
  import React from 'react';
2
2
 
3
3
  import { WizardNavItemType } from './types';
4
- import { WizardBody, WizardBodyProps } from './WizardBody';
5
- import { useWizardFooter } from './hooks/useWizardFooter';
4
+ import { WizardBodyProps } from './WizardBody';
6
5
  import { useWizardContext } from './WizardContext';
7
6
  import { WizardFooterProps } from './WizardFooter';
8
7
 
@@ -23,8 +22,6 @@ export interface WizardStepProps {
23
22
  steps?: React.ReactElement<WizardStepProps>[];
24
23
  /** Flag to disable the step's navigation item */
25
24
  isDisabled?: boolean;
26
- /** Flag to represent whether the step has been visited (navigated to) */
27
- isVisited?: boolean;
28
25
  /** Flag to determine whether the step is hidden */
29
26
  isHidden?: boolean;
30
27
  /** Replaces the step's navigation item or its properties. */
@@ -35,34 +32,26 @@ export interface WizardStepProps {
35
32
  status?: 'default' | 'error';
36
33
  }
37
34
 
38
- export const WizardStep = ({ children, body, id, footer, isHidden, isDisabled, navItem, status }: WizardStepProps) => {
39
- const { currentStep, setStep, toggleStep } = useWizardContext();
35
+ export const WizardStep = ({ children, steps: _subSteps, ...props }: WizardStepProps) => {
36
+ const { activeStep, setStep } = useWizardContext();
37
+ const { id, name, body, isDisabled, isHidden, navItem, footer, status } = props;
40
38
 
41
- useWizardFooter(footer, id);
42
-
43
- // Update the controlled step when a change is detected with select properties
44
- React.useEffect(() => {
45
- if (currentStep?.id === id && (isDisabled || navItem || status || !currentStep?.isVisited)) {
46
- setStep({
47
- id,
48
- ...(isDisabled && { isDisabled }),
49
- ...(navItem && { navItem }),
50
- ...(status && { status }),
51
- // When the current step is active and isn't visited, set as isVisited
52
- ...(!currentStep?.isVisited && { isVisited: true })
53
- });
54
- }
55
- }, [id, setStep, currentStep?.id, isDisabled, navItem, status, currentStep?.isVisited]);
56
-
57
- // Toggle visibility when the isHidden flag updates.
58
- // Wizard's hasUnmountedSteps prop must be set to false for visibility changes to take effect.
39
+ // Update step in context when props change or when the step is active has yet to be marked as visited.
59
40
  React.useEffect(() => {
60
- if (isHidden !== undefined) {
61
- toggleStep(id, isHidden);
62
- }
63
- }, [toggleStep, id, isHidden]);
64
-
65
- return body || body === undefined ? <WizardBody {...body}>{children}</WizardBody> : <>{children}</>;
41
+ setStep({
42
+ id,
43
+ name,
44
+ ...(body && { body }),
45
+ ...(isDisabled && { isDisabled }),
46
+ ...(isHidden && { isHidden }),
47
+ ...(navItem && { navItem }),
48
+ ...(footer && { footer }),
49
+ ...(status && { status }),
50
+ ...(id === activeStep?.id && !activeStep?.isVisited && { isVisited: true })
51
+ });
52
+ }, [body, footer, id, isDisabled, isHidden, name, navItem, status, activeStep?.id, activeStep?.isVisited, setStep]);
53
+
54
+ return <>{children}</>;
66
55
  };
67
56
 
68
57
  WizardStep.displayName = 'WizardStep';
@@ -6,7 +6,7 @@ import AngleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-right-i
6
6
  import CaretDownIcon from '@patternfly/react-icons/dist/esm/icons/caret-down-icon';
7
7
 
8
8
  import { KeyTypes } from '../../../helpers/constants';
9
- import { WizardNavProps } from '../Wizard';
9
+ import { WizardNavProps, WizardBody, WizardStep, WizardStepProps } from '../Wizard';
10
10
  import { WizardControlStep, isWizardSubStep } from './types';
11
11
 
12
12
  /**
@@ -17,15 +17,13 @@ export interface WizardToggleProps {
17
17
  /** List of steps and/or sub-steps */
18
18
  steps: WizardControlStep[];
19
19
  /** The current step */
20
- currentStep: WizardControlStep;
20
+ activeStep: WizardControlStep;
21
21
  /** Wizard footer */
22
22
  footer: React.ReactElement;
23
23
  /** Wizard navigation */
24
24
  nav: React.ReactElement<WizardNavProps>;
25
25
  /** The expandable dropdown button's aria-label */
26
26
  'aria-label'?: string;
27
- /** Flag to unmount inactive steps instead of hiding. Defaults to true */
28
- hasUnmountedSteps?: boolean;
29
27
  /** Flag to determine whether the dropdown navigation is expanded */
30
28
  isNavExpanded?: boolean;
31
29
  /** Callback to expand or collapse the dropdown navigation */
@@ -34,25 +32,24 @@ export interface WizardToggleProps {
34
32
 
35
33
  export const WizardToggle = ({
36
34
  steps,
37
- currentStep,
35
+ activeStep,
38
36
  footer,
39
37
  nav,
40
38
  isNavExpanded,
41
39
  toggleNavExpanded,
42
- hasUnmountedSteps = true,
43
40
  'aria-label': ariaLabel = 'Wizard toggle'
44
41
  }: WizardToggleProps) => {
45
- const isActiveSubStep = isWizardSubStep(currentStep);
42
+ const isActiveSubStep = isWizardSubStep(activeStep);
46
43
  const nonSubSteps = steps.filter(step => !isWizardSubStep(step));
47
44
  const wizardToggleIndex =
48
45
  nonSubSteps.indexOf(
49
- isWizardSubStep(currentStep) ? steps.find(step => step.id === currentStep.parentId) : currentStep
46
+ isWizardSubStep(activeStep) ? steps.find(step => step.id === activeStep.parentId) : activeStep
50
47
  ) + 1;
51
48
 
52
49
  const handleKeyClicks = React.useCallback(
53
50
  (event: KeyboardEvent): void => {
54
51
  if (isNavExpanded && event.key === KeyTypes.Escape) {
55
- toggleNavExpanded();
52
+ toggleNavExpanded?.();
56
53
  }
57
54
  },
58
55
  [isNavExpanded, toggleNavExpanded]
@@ -68,20 +65,21 @@ export const WizardToggle = ({
68
65
  };
69
66
  }, [handleKeyClicks]);
70
67
 
71
- // Only render the current step when hasUnmountedSteps is true
72
- const bodyContent = hasUnmountedSteps
73
- ? currentStep?.component
74
- : steps.map(step => {
75
- if (currentStep?.name === step.name) {
76
- return step.component;
77
- }
68
+ const bodyContent = steps.map(step => {
69
+ const props: WizardStepProps = step.component?.props || {};
70
+ const { children, body, ...propsWithoutChildren } = props;
78
71
 
79
- return (
80
- <div key={step.id} style={{ display: 'none' }}>
81
- {step.component}
82
- </div>
83
- );
84
- });
72
+ return (
73
+ <React.Fragment key={step.id}>
74
+ {activeStep?.name === step.name &&
75
+ (body || body === undefined ? <WizardBody {...body}>{children}</WizardBody> : children)}
76
+
77
+ <div key={step.id} style={{ display: 'none' }}>
78
+ <WizardStep {...propsWithoutChildren} />
79
+ </div>
80
+ </React.Fragment>
81
+ );
82
+ });
85
83
 
86
84
  return (
87
85
  <>
@@ -93,10 +91,10 @@ export const WizardToggle = ({
93
91
  >
94
92
  <span className={css(styles.wizardToggleList)}>
95
93
  <span className={css(styles.wizardToggleListItem)}>
96
- <span className={css(styles.wizardToggleNum)}>{wizardToggleIndex}</span> {currentStep?.name}
94
+ <span className={css(styles.wizardToggleNum)}>{wizardToggleIndex}</span> {activeStep?.name}
97
95
  {isActiveSubStep && <AngleRightIcon className={css(styles.wizardToggleSeparator)} aria-hidden="true" />}
98
96
  </span>
99
- {isActiveSubStep && <span className={css(styles.wizardToggleListItem)}>{currentStep?.name}</span>}
97
+ {isActiveSubStep && <span className={css(styles.wizardToggleListItem)}>{activeStep?.name}</span>}
100
98
  </span>
101
99
 
102
100
  <span className={css(styles.wizardToggleIcon)}>
@@ -111,7 +111,7 @@ test('renders default nav with custom props', () => {
111
111
 
112
112
  expect(navElement).toBeVisible();
113
113
  expect(navElement).toHaveAttribute('aria-labelledby', 'wizard-id');
114
- expect(screen.getByRole('button', { name: 'Test step 1' }).parentElement).toHaveClass('pf-m-expandable');
114
+ expect(screen.getByRole('button', { name: 'Test step 1, visited' }).parentElement).toHaveClass('pf-m-expandable');
115
115
  expect(screen.getByRole('button', { name: 'Test step 2' })).toHaveAttribute('disabled');
116
116
  });
117
117
 
@@ -297,23 +297,3 @@ 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('keeps inactive steps mounted when hasUnmountedSteps is enabled', async () => {
302
- const user = userEvent.setup();
303
-
304
- render(
305
- <Wizard hasUnmountedSteps={false}>
306
- <WizardStep id="step-1" name="Test step 1">
307
- Step 1 content
308
- </WizardStep>
309
- <WizardStep id="step-2" name="Test step 2">
310
- Step 2 content
311
- </WizardStep>
312
- </Wizard>
313
- );
314
-
315
- await user.click(screen.getByRole('button', { name: 'Test step 2' }));
316
-
317
- expect(screen.getByText('Step 1 content')).toBeInTheDocument();
318
- expect(screen.getByText('Step 2 content')).toBeVisible();
319
- });
@@ -15,8 +15,8 @@ test('has no padding className when hasNoBodyPadding is not specified', () => {
15
15
  expect(screen.getByText('content')).not.toHaveClass('pf-m-no-padding');
16
16
  });
17
17
 
18
- test('has padding className when hasNoBodyPadding is specified', () => {
19
- render(<WizardBody hasNoBodyPadding>content</WizardBody>);
18
+ test('has padding className when hasNoPadding is specified', () => {
19
+ render(<WizardBody hasNoPadding>content</WizardBody>);
20
20
  expect(screen.getByText('content')).toHaveClass('pf-m-no-padding');
21
21
  });
22
22
 
@@ -6,7 +6,7 @@ import userEvent from '@testing-library/user-event';
6
6
  import { WizardFooter, WizardFooterProps } from '../WizardFooter';
7
7
 
8
8
  const defaultProps: WizardFooterProps = {
9
- currentStep: { name: 'Step name', id: 'some-id' },
9
+ activeStep: { name: 'Step name', id: 'some-id', index: 1 },
10
10
  onNext: jest.fn(),
11
11
  onBack: jest.fn(),
12
12
  onClose: jest.fn()
@@ -70,19 +70,19 @@ test('has disabled back button when isBackDisabled is enabled', () => {
70
70
  expect(screen.getByRole('button', { name: 'Back' })).toHaveAttribute('disabled');
71
71
  });
72
72
 
73
- test('uses currentStep footer properties when specified', () => {
73
+ test('uses activeStep footer properties when specified', () => {
74
74
  render(
75
- <WizardFooter {...defaultProps} currentStep={{ ...defaultProps.currentStep, footer: { isBackHidden: true } }} />
75
+ <WizardFooter {...defaultProps} activeStep={{ ...defaultProps.activeStep, footer: { isBackHidden: true } }} />
76
76
  );
77
77
  expect(screen.queryByRole('button', { name: 'Back' })).toBeNull();
78
78
  });
79
79
 
80
- test(`currentStep footer properties take precendence over WizardFooter's`, () => {
80
+ test(`activeStep footer properties take precendence over WizardFooter's`, () => {
81
81
  render(
82
82
  <WizardFooter
83
83
  {...defaultProps}
84
84
  nextButtonText="Footer next"
85
- currentStep={{ ...defaultProps.currentStep, footer: { nextButtonText: 'Active step next' } }}
85
+ activeStep={{ ...defaultProps.activeStep, footer: { nextButtonText: 'Active step next' } }}
86
86
  />
87
87
  );
88
88
  expect(screen.queryByRole('button', { name: 'Footer next' })).toBeNull();
@@ -2,20 +2,27 @@ import React from 'react';
2
2
 
3
3
  import { render, screen } from '@testing-library/react';
4
4
 
5
- import { WizardStep } from '../WizardStep';
6
- import * as useWizardFooter from '../hooks/useWizardFooter';
5
+ import { WizardStep, WizardStepProps } from '../WizardStep';
7
6
  import * as WizardContext from '../WizardContext';
8
- import { WizardStepProps } from '..';
7
+ import { WizardControlStep } from '..';
9
8
 
10
- const testStep: WizardStepProps = {
9
+ const testStepProps: WizardStepProps = {
11
10
  id: 'test-step',
12
11
  name: 'Test step',
13
12
  footer: <>Step footer</>
14
13
  };
14
+
15
+ const testStep: WizardControlStep = {
16
+ ...testStepProps,
17
+ index: 1
18
+ };
19
+
20
+ const setStep = jest.fn();
21
+
15
22
  const wizardContext: WizardContext.WizardContextProps = {
23
+ setStep,
16
24
  steps: [testStep],
17
- currentStep: testStep,
18
- currentStepIndex: 1,
25
+ activeStep: testStep,
19
26
  footer: <>Wizard footer</>,
20
27
  onNext: jest.fn(),
21
28
  onBack: jest.fn(),
@@ -25,11 +32,14 @@ const wizardContext: WizardContext.WizardContextProps = {
25
32
  goToStepByIndex: jest.fn(),
26
33
  setFooter: jest.fn(),
27
34
  getStep: jest.fn(),
28
- setStep: jest.fn(),
29
- toggleStep: jest.fn()
35
+ setSteps: jest.fn()
30
36
  };
37
+
31
38
  const useWizardContextSpy = jest.spyOn(WizardContext, 'useWizardContext');
32
- const useWizardFooterSpy = jest.spyOn(useWizardFooter, 'useWizardFooter');
39
+
40
+ beforeEach(() => {
41
+ useWizardContextSpy.mockReturnValue(wizardContext);
42
+ });
33
43
 
34
44
  test('renders without children', () => {
35
45
  const { container } = render(<WizardStep id="test-step" name="Test step" />);
@@ -51,83 +61,19 @@ test('excludes WizardBody when body is set to null', () => {
51
61
  expect(screen.queryByRole('main')).toBeNull();
52
62
  });
53
63
 
54
- test('uses body props for WizardBody when passed', () => {
55
- render(
56
- <WizardStep id="test-step" name="Test step" body={{ 'aria-label': 'Some label' }}>
57
- content
58
- </WizardStep>
59
- );
60
-
61
- expect(screen.getByLabelText('Some label')).toBeVisible();
62
- });
63
-
64
- test('calls useWizardFooter', () => {
65
- useWizardContextSpy.mockReturnValueOnce(wizardContext);
66
-
67
- render(<WizardStep {...testStep}>content</WizardStep>);
68
- expect(useWizardFooterSpy).toHaveBeenCalledWith(testStep.footer, 'test-step');
69
- });
70
-
71
64
  test('updates "isDisabled" in context when the value changes', () => {
72
- const setStep = jest.fn();
73
- useWizardContextSpy.mockReturnValueOnce({ ...wizardContext, setStep });
74
-
75
65
  render(<WizardStep {...testStep} isDisabled />);
76
-
77
- expect(setStep).toHaveBeenCalledWith({ id: testStep.id, isDisabled: true, isVisited: true });
66
+ expect(setStep).toHaveBeenCalledWith({ ...testStepProps, isDisabled: true, isVisited: true });
78
67
  });
79
68
 
80
69
  test('updates "navItem" in context when the value changes', () => {
81
- const setStep = jest.fn();
82
70
  const testNavItem = <>Some nav item</>;
83
- useWizardContextSpy.mockReturnValueOnce({ ...wizardContext, setStep });
84
-
85
71
  render(<WizardStep {...testStep} navItem={testNavItem} />);
86
72
 
87
- expect(setStep).toHaveBeenCalledWith({ id: testStep.id, navItem: testNavItem, isVisited: true });
73
+ expect(setStep).toHaveBeenCalledWith({ ...testStepProps, navItem: testNavItem, isVisited: true });
88
74
  });
89
75
 
90
76
  test('updates "status" in context when the value changes', () => {
91
- const setStep = jest.fn();
92
- useWizardContextSpy.mockReturnValueOnce({ ...wizardContext, setStep });
93
-
94
77
  render(<WizardStep {...testStep} status="error" />);
95
-
96
- expect(setStep).toHaveBeenCalledWith({ id: testStep.id, status: 'error', isVisited: true });
97
- });
98
-
99
- test('calls "toggleStep" when isHidden value changes and the previous value was not undefined', () => {
100
- const toggleStep = jest.fn();
101
- useWizardContextSpy.mockReturnValueOnce({ ...wizardContext, toggleStep });
102
-
103
- render(<WizardStep {...testStep} isHidden />);
104
-
105
- expect(toggleStep).toHaveBeenCalledWith(testStep.id, true);
106
- });
107
-
108
- test('does not call "toggleStep" when isHidden value changes and was previously undefined', () => {
109
- const toggleStep = jest.fn();
110
- useWizardContextSpy.mockReturnValueOnce({
111
- ...wizardContext,
112
- toggleStep
113
- });
114
-
115
- render(<WizardStep {...testStep} isHidden={undefined} />);
116
-
117
- expect(toggleStep).not.toHaveBeenCalled();
118
- });
119
-
120
- test('does not update "isVisited" value in context when the step was previously visited', () => {
121
- const setStep = jest.fn();
122
- const visitedTestStep = { ...testStep, isVisited: true };
123
- useWizardContextSpy.mockReturnValueOnce({
124
- ...wizardContext,
125
- currentStep: visitedTestStep,
126
- steps: [visitedTestStep],
127
- setStep
128
- });
129
-
130
- render(<WizardStep {...visitedTestStep} />);
131
-
132
- expect(setStep).not.toHaveBeenCalled();
78
+ expect(setStep).toHaveBeenCalledWith({ ...testStepProps, status: 'error', isVisited: true });
133
79
  });
@@ -5,20 +5,23 @@ import userEvent from '@testing-library/user-event';
5
5
 
6
6
  import { KeyTypes } from '../../../../helpers';
7
7
  import { WizardToggle, WizardToggleProps } from '../WizardToggle';
8
+ import { WizardControlStep } from '../types';
8
9
 
9
- const steps = [
10
- { id: 'id-1', name: 'First step', component: <>First step content</> },
11
- { id: 'id-2', name: 'Second step', component: <>Second step content</> }
10
+ const steps: WizardControlStep[] = [
11
+ { id: 'id-1', name: 'First step', index: 1, component: <>First step content</> },
12
+ { id: 'id-2', name: 'Second step', index: 2, component: <>Second step content</> }
12
13
  ];
13
14
 
14
15
  const defaultProps: WizardToggleProps = {
15
16
  steps,
16
- currentStep: steps[0],
17
+ activeStep: steps[0],
17
18
  footer: <div>Some footer</div>,
18
19
  nav: <div>Some nav</div>,
19
20
  'aria-label': 'Some label'
20
21
  };
21
22
 
23
+ jest.mock('../WizardStep', () => ({ WizardStep: () => <div>step stub</div> }));
24
+
22
25
  test('renders provided footer, nav, and current step content', () => {
23
26
  render(<WizardToggle {...defaultProps} />);
24
27
 
@@ -58,13 +61,6 @@ test('renders only the active step content by default', async () => {
58
61
  expect(screen.queryByText('Second step content')).toBeNull;
59
62
  });
60
63
 
61
- test('renders all step content when hasUnmountedSteps is false', async () => {
62
- render(<WizardToggle {...defaultProps} hasUnmountedSteps={false} />);
63
-
64
- expect(screen.getByText('First step content')).toBeInTheDocument();
65
- expect(screen.getByText('Second step content')).toBeInTheDocument();
66
- });
67
-
68
64
  test('has expanded properties when the toggle dropdown button is clicked', async () => {
69
65
  const user = userEvent.setup();
70
66
 
@@ -9,7 +9,7 @@ describe('buildSteps', () => {
9
9
  try {
10
10
  buildSteps(<div />);
11
11
  } catch (error) {
12
- expect(error.message).toEqual('Wizard only accepts children of type WizardStep');
12
+ expect(error.message).toEqual('Wizard only accepts children with required WizardStepProps.');
13
13
  }
14
14
  });
15
15
 
@@ -17,7 +17,7 @@ describe('buildSteps', () => {
17
17
  try {
18
18
  buildSteps('test' as any);
19
19
  } catch (error) {
20
- expect(error.message).toEqual('Wizard only accepts children of type WizardStep');
20
+ expect(error.message).toEqual('Wizard only accepts children with required WizardStepProps.');
21
21
  }
22
22
  });
23
23
 
@@ -57,7 +57,7 @@ describe('buildSteps', () => {
57
57
  ]}
58
58
  />
59
59
  );
60
- const [subStep, customSubStep, parentStep] = buildSteps(component);
60
+ const [parentStep, subStep, customSubStep] = buildSteps(component);
61
61
 
62
62
  expect((subStep as WizardSubStep).parentId).toEqual('step-1');
63
63
  expect((customSubStep as WizardSubStep).parentId).toEqual('step-1');
@@ -68,7 +68,7 @@ The `Wizard`'s `nav` property can be used to build your own navigation.
68
68
  export type CustomWizardNavFunction = (
69
69
  isExpanded: boolean,
70
70
  steps: WizardControlStep[],
71
- currentStep: WizardControlStep,
71
+ activeStep: WizardControlStep,
72
72
  goToStepByIndex: (index: number) => void
73
73
  ) => React.ReactElement<WizardNavProps>;
74
74
 
@@ -110,7 +110,7 @@ The `WizardStep`'s `navItem` property can be used to build your own nav item for
110
110
  /** Callback for the Wizard's 'navItem' property. Returns element which replaces the WizardStep's default navItem. */
111
111
  export type CustomWizardNavItemFunction = (
112
112
  step: WizardControlStep,
113
- currentStep: WizardControlStep,
113
+ activeStep: WizardControlStep,
114
114
  steps: WizardControlStep[],
115
115
  goToStepByIndex: (index: number) => void
116
116
  ) => React.ReactElement<WizardNavItemProps>;
@@ -129,8 +129,8 @@ Used to access any property of [WizardContext](#wizardcontextprops):
129
129
  import { useWizardContext } from '@patternfly/react-core/next';
130
130
 
131
131
  const StepContent = () => {
132
- const { currentStep } = useWizardContext();
133
- return <>This is the current step: {currentStep}</>;
132
+ const { activeStep } = useWizardContext();
133
+ return <>This is the current step: {activeStep}</>;
134
134
  }
135
135
  ```
136
136
 
@@ -12,18 +12,18 @@ export const WizardCustomNav: React.FunctionComponent = () => {
12
12
  const nav: CustomWizardNavFunction = (
13
13
  isExpanded: boolean,
14
14
  steps: WizardControlStep[],
15
- currentStep: WizardControlStep,
15
+ activeStep: WizardControlStep,
16
16
  goToStepByIndex: (index: number) => void
17
17
  ) => (
18
18
  <WizardNav isExpanded={isExpanded}>
19
- {steps.map((step, index) => (
19
+ {steps.map(step => (
20
20
  <WizardNavItem
21
21
  key={step.id}
22
22
  id={step.id}
23
23
  content={step.name}
24
- isCurrent={currentStep.id === step.id}
24
+ isCurrent={activeStep.id === step.id}
25
25
  isDisabled={step.isDisabled}
26
- stepIndex={index + 1}
26
+ stepIndex={step.index}
27
27
  onNavItemClick={goToStepByIndex}
28
28
  />
29
29
  ))}