@patternfly/react-core 4.255.1 → 4.256.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.
- package/CHANGELOG.md +19 -0
- package/dist/esm/components/Card/Card.d.ts +2 -2
- package/dist/esm/components/Card/Card.d.ts.map +1 -1
- package/dist/esm/components/DataList/DataList.d.ts +1 -1
- package/dist/esm/components/DataList/DataList.d.ts.map +1 -1
- package/dist/esm/components/DataList/DataListItem.d.ts +1 -1
- package/dist/esm/components/DataList/DataListItem.d.ts.map +1 -1
- package/dist/esm/components/MultipleFileUpload/MultipleFileUploadStatusItem.d.ts +2 -0
- package/dist/esm/components/MultipleFileUpload/MultipleFileUploadStatusItem.d.ts.map +1 -1
- package/dist/esm/components/MultipleFileUpload/MultipleFileUploadStatusItem.js +7 -1
- package/dist/esm/components/MultipleFileUpload/MultipleFileUploadStatusItem.js.map +1 -1
- package/dist/esm/components/Popover/Popover.d.ts +3 -3
- package/dist/esm/components/Popover/Popover.d.ts.map +1 -1
- package/dist/esm/components/Wizard/Wizard.d.ts +4 -4
- package/dist/esm/components/Wizard/Wizard.d.ts.map +1 -1
- package/dist/esm/components/Wizard/WizardToggle.d.ts +2 -2
- package/dist/esm/components/Wizard/WizardToggle.d.ts.map +1 -1
- package/dist/esm/next/components/Wizard/Wizard.d.ts +1 -3
- package/dist/esm/next/components/Wizard/Wizard.d.ts.map +1 -1
- package/dist/esm/next/components/Wizard/Wizard.js +36 -45
- package/dist/esm/next/components/Wizard/Wizard.js.map +1 -1
- package/dist/esm/next/components/Wizard/WizardBody.d.ts +2 -2
- package/dist/esm/next/components/Wizard/WizardBody.d.ts.map +1 -1
- package/dist/esm/next/components/Wizard/WizardBody.js +2 -2
- package/dist/esm/next/components/Wizard/WizardBody.js.map +1 -1
- package/dist/esm/next/components/Wizard/WizardContext.d.ts +2 -7
- package/dist/esm/next/components/Wizard/WizardContext.d.ts.map +1 -1
- package/dist/esm/next/components/Wizard/WizardContext.js +18 -39
- package/dist/esm/next/components/Wizard/WizardContext.js.map +1 -1
- package/dist/esm/next/components/Wizard/WizardFooter.d.ts +3 -3
- package/dist/esm/next/components/Wizard/WizardFooter.d.ts.map +1 -1
- package/dist/esm/next/components/Wizard/WizardFooter.js +3 -3
- package/dist/esm/next/components/Wizard/WizardFooter.js.map +1 -1
- package/dist/esm/next/components/Wizard/WizardNavInternal.d.ts.map +1 -1
- package/dist/esm/next/components/Wizard/WizardNavInternal.js +12 -12
- package/dist/esm/next/components/Wizard/WizardNavInternal.js.map +1 -1
- package/dist/esm/next/components/Wizard/WizardStep.d.ts +1 -3
- package/dist/esm/next/components/Wizard/WizardStep.d.ts.map +1 -1
- package/dist/esm/next/components/Wizard/WizardStep.js +10 -18
- package/dist/esm/next/components/Wizard/WizardStep.js.map +1 -1
- package/dist/esm/next/components/Wizard/WizardToggle.d.ts +2 -4
- package/dist/esm/next/components/Wizard/WizardToggle.d.ts.map +1 -1
- package/dist/esm/next/components/Wizard/WizardToggle.js +19 -16
- package/dist/esm/next/components/Wizard/WizardToggle.js.map +1 -1
- package/dist/esm/next/components/Wizard/hooks/useWizardFooter.js +3 -3
- package/dist/esm/next/components/Wizard/hooks/useWizardFooter.js.map +1 -1
- package/dist/esm/next/components/Wizard/types.d.ts +5 -3
- package/dist/esm/next/components/Wizard/types.d.ts.map +1 -1
- package/dist/esm/next/components/Wizard/types.js.map +1 -1
- package/dist/esm/next/components/Wizard/utils.d.ts +3 -3
- package/dist/esm/next/components/Wizard/utils.d.ts.map +1 -1
- package/dist/esm/next/components/Wizard/utils.js +14 -11
- package/dist/esm/next/components/Wizard/utils.js.map +1 -1
- package/dist/js/components/Card/Card.d.ts +2 -2
- package/dist/js/components/Card/Card.d.ts.map +1 -1
- package/dist/js/components/DataList/DataList.d.ts +1 -1
- package/dist/js/components/DataList/DataList.d.ts.map +1 -1
- package/dist/js/components/DataList/DataListItem.d.ts +1 -1
- package/dist/js/components/DataList/DataListItem.d.ts.map +1 -1
- package/dist/js/components/MultipleFileUpload/MultipleFileUploadStatusItem.d.ts +2 -0
- package/dist/js/components/MultipleFileUpload/MultipleFileUploadStatusItem.d.ts.map +1 -1
- package/dist/js/components/MultipleFileUpload/MultipleFileUploadStatusItem.js +7 -1
- package/dist/js/components/MultipleFileUpload/MultipleFileUploadStatusItem.js.map +1 -1
- package/dist/js/components/Popover/Popover.d.ts +3 -3
- package/dist/js/components/Popover/Popover.d.ts.map +1 -1
- package/dist/js/components/Wizard/Wizard.d.ts +4 -4
- package/dist/js/components/Wizard/Wizard.d.ts.map +1 -1
- package/dist/js/components/Wizard/WizardToggle.d.ts +2 -2
- package/dist/js/components/Wizard/WizardToggle.d.ts.map +1 -1
- package/dist/js/next/components/Wizard/Wizard.d.ts +1 -3
- package/dist/js/next/components/Wizard/Wizard.d.ts.map +1 -1
- package/dist/js/next/components/Wizard/Wizard.js +36 -45
- package/dist/js/next/components/Wizard/Wizard.js.map +1 -1
- package/dist/js/next/components/Wizard/WizardBody.d.ts +2 -2
- package/dist/js/next/components/Wizard/WizardBody.d.ts.map +1 -1
- package/dist/js/next/components/Wizard/WizardBody.js +2 -2
- package/dist/js/next/components/Wizard/WizardBody.js.map +1 -1
- package/dist/js/next/components/Wizard/WizardContext.d.ts +2 -7
- package/dist/js/next/components/Wizard/WizardContext.d.ts.map +1 -1
- package/dist/js/next/components/Wizard/WizardContext.js +15 -37
- package/dist/js/next/components/Wizard/WizardContext.js.map +1 -1
- package/dist/js/next/components/Wizard/WizardFooter.d.ts +3 -3
- package/dist/js/next/components/Wizard/WizardFooter.d.ts.map +1 -1
- package/dist/js/next/components/Wizard/WizardFooter.js +3 -3
- package/dist/js/next/components/Wizard/WizardFooter.js.map +1 -1
- package/dist/js/next/components/Wizard/WizardNavInternal.d.ts.map +1 -1
- package/dist/js/next/components/Wizard/WizardNavInternal.js +12 -12
- package/dist/js/next/components/Wizard/WizardNavInternal.js.map +1 -1
- package/dist/js/next/components/Wizard/WizardStep.d.ts +1 -3
- package/dist/js/next/components/Wizard/WizardStep.d.ts.map +1 -1
- package/dist/js/next/components/Wizard/WizardStep.js +9 -18
- package/dist/js/next/components/Wizard/WizardStep.js.map +1 -1
- package/dist/js/next/components/Wizard/WizardToggle.d.ts +2 -4
- package/dist/js/next/components/Wizard/WizardToggle.d.ts.map +1 -1
- package/dist/js/next/components/Wizard/WizardToggle.js +18 -16
- package/dist/js/next/components/Wizard/WizardToggle.js.map +1 -1
- package/dist/js/next/components/Wizard/hooks/useWizardFooter.js +3 -3
- package/dist/js/next/components/Wizard/hooks/useWizardFooter.js.map +1 -1
- package/dist/js/next/components/Wizard/types.d.ts +5 -3
- package/dist/js/next/components/Wizard/types.d.ts.map +1 -1
- package/dist/js/next/components/Wizard/types.js.map +1 -1
- package/dist/js/next/components/Wizard/utils.d.ts +3 -3
- package/dist/js/next/components/Wizard/utils.d.ts.map +1 -1
- package/dist/js/next/components/Wizard/utils.js +16 -13
- package/dist/js/next/components/Wizard/utils.js.map +1 -1
- package/dist/umd/react-core.min.css +137 -137
- package/dist/umd/react-core.min.js +1 -1
- package/package.json +2 -2
- package/src/components/AlertGroup/examples/AlertGroup.md +2 -2
- package/src/components/CalendarMonth/examples/CalendarMonth.md +0 -1
- package/src/components/Card/Card.tsx +2 -2
- package/src/components/DataList/DataList.tsx +1 -1
- package/src/components/DataList/DataListItem.tsx +1 -1
- package/src/components/DualListSelector/examples/DualListSelector.md +0 -1
- package/src/components/LabelGroup/examples/LabelGroup.md +2 -3
- package/src/components/Masthead/examples/Masthead.md +0 -1
- package/src/components/Menu/examples/Menu.md +1 -1
- package/src/components/MenuToggle/examples/MenuToggle.md +0 -1
- package/src/components/MultipleFileUpload/MultipleFileUploadStatusItem.tsx +10 -0
- package/src/components/MultipleFileUpload/__tests__/MultipleFileUploadStatusItem.test.tsx +33 -1
- package/src/components/MultipleFileUpload/__tests__/__snapshots__/MultipleFileUploadStatusItem.test.tsx.snap +269 -3
- package/src/components/MultipleFileUpload/examples/MultipleFileUpload.md +0 -1
- package/src/components/NotificationDrawer/examples/NotificationDrawer.md +0 -1
- package/src/components/Panel/examples/Panel.md +0 -1
- package/src/components/Popover/Popover.tsx +3 -3
- package/src/components/Popover/examples/Popover.md +2 -2
- package/src/components/Select/examples/Select.md +2 -2
- package/src/components/Slider/examples/Slider.md +0 -1
- package/src/components/TextArea/examples/TextArea.md +1 -1
- package/src/components/TextInput/examples/TextInput.md +1 -1
- package/src/components/TreeView/examples/TreeView.md +0 -1
- package/src/components/Wizard/Wizard.tsx +4 -4
- package/src/components/Wizard/WizardToggle.tsx +2 -2
- package/src/components/Wizard/examples/Wizard.md +12 -8
- package/src/demos/MultipleFileUploadDemos.md +0 -1
- package/src/demos/NotificationDrawer/NotificationDrawer.md +0 -1
- package/src/next/components/Wizard/Wizard.tsx +35 -54
- package/src/next/components/Wizard/WizardBody.tsx +3 -3
- package/src/next/components/Wizard/WizardContext.tsx +29 -61
- package/src/next/components/Wizard/WizardFooter.tsx +6 -6
- package/src/next/components/Wizard/WizardNavInternal.tsx +18 -17
- package/src/next/components/Wizard/WizardStep.tsx +19 -30
- package/src/next/components/Wizard/WizardToggle.tsx +22 -24
- package/src/next/components/Wizard/__tests__/Wizard.test.tsx +1 -21
- package/src/next/components/Wizard/__tests__/WizardBody.test.tsx +2 -2
- package/src/next/components/Wizard/__tests__/WizardFooter.test.tsx +5 -5
- package/src/next/components/Wizard/__tests__/WizardStep.test.tsx +22 -76
- package/src/next/components/Wizard/__tests__/WizardToggle.test.tsx +7 -11
- package/src/next/components/Wizard/__tests__/utils.test.tsx +3 -3
- package/src/next/components/Wizard/examples/Wizard.md +4 -4
- package/src/next/components/Wizard/examples/WizardCustomNav.tsx +4 -4
- package/src/next/components/Wizard/examples/WizardKitchenSink.tsx +74 -85
- package/src/next/components/Wizard/hooks/__tests__/useWizardFooter.test.tsx +4 -4
- package/src/next/components/Wizard/hooks/useWizardFooter.tsx +3 -3
- package/src/next/components/Wizard/types.tsx +5 -3
- 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 {
|
|
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,
|
|
39
|
-
const {
|
|
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
|
-
|
|
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
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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(
|
|
42
|
+
const isActiveSubStep = isWizardSubStep(activeStep);
|
|
46
43
|
const nonSubSteps = steps.filter(step => !isWizardSubStep(step));
|
|
47
44
|
const wizardToggleIndex =
|
|
48
45
|
nonSubSteps.indexOf(
|
|
49
|
-
isWizardSubStep(
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
</
|
|
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> {
|
|
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)}>{
|
|
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
|
|
19
|
-
render(<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
|
-
|
|
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
|
|
73
|
+
test('uses activeStep footer properties when specified', () => {
|
|
74
74
|
render(
|
|
75
|
-
<WizardFooter {...defaultProps}
|
|
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(`
|
|
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
|
-
|
|
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 {
|
|
7
|
+
import { WizardControlStep } from '..';
|
|
9
8
|
|
|
10
|
-
const
|
|
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
|
-
|
|
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
|
-
|
|
29
|
-
toggleStep: jest.fn()
|
|
35
|
+
setSteps: jest.fn()
|
|
30
36
|
};
|
|
37
|
+
|
|
31
38
|
const useWizardContextSpy = jest.spyOn(WizardContext, 'useWizardContext');
|
|
32
|
-
|
|
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({
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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 {
|
|
133
|
-
return <>This is the current step: {
|
|
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
|
-
|
|
15
|
+
activeStep: WizardControlStep,
|
|
16
16
|
goToStepByIndex: (index: number) => void
|
|
17
17
|
) => (
|
|
18
18
|
<WizardNav isExpanded={isExpanded}>
|
|
19
|
-
{steps.map(
|
|
19
|
+
{steps.map(step => (
|
|
20
20
|
<WizardNavItem
|
|
21
21
|
key={step.id}
|
|
22
22
|
id={step.id}
|
|
23
23
|
content={step.name}
|
|
24
|
-
isCurrent={
|
|
24
|
+
isCurrent={activeStep.id === step.id}
|
|
25
25
|
isDisabled={step.isDisabled}
|
|
26
|
-
stepIndex={index
|
|
26
|
+
stepIndex={step.index}
|
|
27
27
|
onNavItemClick={goToStepByIndex}
|
|
28
28
|
/>
|
|
29
29
|
))}
|