@patternfly/react-core 4.224.13 → 4.224.14
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 +8 -0
- package/dist/esm/components/Wizard/Wizard.d.ts +2 -0
- package/dist/esm/components/Wizard/Wizard.d.ts.map +1 -1
- package/dist/esm/components/Wizard/Wizard.js +26 -5
- package/dist/esm/components/Wizard/Wizard.js.map +1 -1
- package/dist/esm/helpers/OUIA/ouia.d.ts.map +1 -1
- package/dist/esm/helpers/OUIA/ouia.js +2 -4
- package/dist/esm/helpers/OUIA/ouia.js.map +1 -1
- package/dist/js/components/Wizard/Wizard.d.ts +2 -0
- package/dist/js/components/Wizard/Wizard.d.ts.map +1 -1
- package/dist/js/components/Wizard/Wizard.js +26 -5
- package/dist/js/components/Wizard/Wizard.js.map +1 -1
- package/dist/js/helpers/OUIA/ouia.d.ts.map +1 -1
- package/dist/js/helpers/OUIA/ouia.js +2 -4
- package/dist/js/helpers/OUIA/ouia.js.map +1 -1
- package/dist/umd/react-core.js +28 -9
- package/dist/umd/react-core.min.js +2 -2
- package/package.json +6 -6
- package/src/components/Wizard/Wizard.tsx +37 -5
- package/src/components/Wizard/__tests__/Wizard.test.tsx +92 -0
- package/src/components/Wizard/examples/Wizard.md +25 -0
- package/src/helpers/OUIA/ouia.ts +2 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@patternfly/react-core",
|
|
3
|
-
"version": "4.224.
|
|
3
|
+
"version": "4.224.14",
|
|
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",
|
|
@@ -34,16 +34,16 @@
|
|
|
34
34
|
"generate": "node scripts/copyStyles.js"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@patternfly/react-icons": "^4.75.
|
|
38
|
-
"@patternfly/react-styles": "^4.74.
|
|
39
|
-
"@patternfly/react-tokens": "^4.76.
|
|
37
|
+
"@patternfly/react-icons": "^4.75.14",
|
|
38
|
+
"@patternfly/react-styles": "^4.74.14",
|
|
39
|
+
"@patternfly/react-tokens": "^4.76.14",
|
|
40
40
|
"focus-trap": "6.9.2",
|
|
41
41
|
"react-dropzone": "9.0.0",
|
|
42
42
|
"tippy.js": "5.1.2",
|
|
43
43
|
"tslib": "^2.0.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@patternfly/patternfly": "4.203.
|
|
46
|
+
"@patternfly/patternfly": "4.203.2",
|
|
47
47
|
"@rollup/plugin-commonjs": "^21.0.0",
|
|
48
48
|
"@rollup/plugin-node-resolve": "^13.0.0",
|
|
49
49
|
"@rollup/plugin-replace": "^3.0.0",
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"react": "^16.8.0 || ^17.0.0",
|
|
61
61
|
"react-dom": "^16.8.0 || ^17.0.0"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "71e3dd5504c0309222ada3cf612717ac220c29fd"
|
|
64
64
|
}
|
|
@@ -38,6 +38,8 @@ export interface WizardStep {
|
|
|
38
38
|
hideCancelButton?: boolean;
|
|
39
39
|
/** (Unused if footer is controlled) True to hide the Back button */
|
|
40
40
|
hideBackButton?: boolean;
|
|
41
|
+
/** Flag to disable the step in the navigation */
|
|
42
|
+
isDisabled?: boolean;
|
|
41
43
|
}
|
|
42
44
|
|
|
43
45
|
export type WizardStepFunctionType = (
|
|
@@ -187,7 +189,19 @@ export class Wizard extends React.Component<WizardProps, WizardState> {
|
|
|
187
189
|
}
|
|
188
190
|
return onClose();
|
|
189
191
|
} else {
|
|
190
|
-
|
|
192
|
+
let newStep = currentStep;
|
|
193
|
+
|
|
194
|
+
for (let nextStep = currentStep; nextStep <= maxSteps; nextStep++) {
|
|
195
|
+
if (!flattenedSteps[nextStep]) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (!flattenedSteps[nextStep].isDisabled) {
|
|
200
|
+
newStep = nextStep + 1;
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
191
205
|
this.setState({
|
|
192
206
|
currentStep: newStep
|
|
193
207
|
});
|
|
@@ -208,7 +222,19 @@ export class Wizard extends React.Component<WizardProps, WizardState> {
|
|
|
208
222
|
currentStep: adjustedStep
|
|
209
223
|
});
|
|
210
224
|
} else {
|
|
211
|
-
|
|
225
|
+
let newStep = currentStep;
|
|
226
|
+
|
|
227
|
+
for (let prevStep = currentStep; prevStep >= 0; prevStep--) {
|
|
228
|
+
if (!flattenedSteps[prevStep - 2]) {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if (!flattenedSteps[prevStep - 2].isDisabled) {
|
|
233
|
+
newStep = prevStep - 1 <= 1 ? 1 : prevStep - 1;
|
|
234
|
+
break;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
212
238
|
this.setState({
|
|
213
239
|
currentStep: newStep
|
|
214
240
|
});
|
|
@@ -219,9 +245,14 @@ export class Wizard extends React.Component<WizardProps, WizardState> {
|
|
|
219
245
|
};
|
|
220
246
|
|
|
221
247
|
private goToStep = (step: number): void => {
|
|
248
|
+
const flattenedSteps = this.getFlattenedSteps();
|
|
249
|
+
|
|
250
|
+
if (flattenedSteps[step - 1].isDisabled) {
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
|
|
222
254
|
const { onGoToStep } = this.props;
|
|
223
255
|
const { currentStep } = this.state;
|
|
224
|
-
const flattenedSteps = this.getFlattenedSteps();
|
|
225
256
|
const maxSteps = flattenedSteps.length;
|
|
226
257
|
if (step < 1) {
|
|
227
258
|
step = 1;
|
|
@@ -413,7 +444,7 @@ export class Wizard extends React.Component<WizardProps, WizardState> {
|
|
|
413
444
|
return;
|
|
414
445
|
}
|
|
415
446
|
navItemStep = this.getFlattenedStepsIndex(flattenedSteps, childStep.name);
|
|
416
|
-
enabled = childStep.canJumpTo;
|
|
447
|
+
enabled = childStep.canJumpTo && !childStep.isDisabled;
|
|
417
448
|
return (
|
|
418
449
|
<WizardNavItem
|
|
419
450
|
key={`child_${indexChild}`}
|
|
@@ -431,7 +462,8 @@ export class Wizard extends React.Component<WizardProps, WizardState> {
|
|
|
431
462
|
);
|
|
432
463
|
}
|
|
433
464
|
navItemStep = this.getFlattenedStepsIndex(flattenedSteps, step.name);
|
|
434
|
-
enabled = step.canJumpTo;
|
|
465
|
+
enabled = step.canJumpTo && !step.isDisabled;
|
|
466
|
+
|
|
435
467
|
return (
|
|
436
468
|
<WizardNavItem
|
|
437
469
|
{...step.stepNavItemProps}
|
|
@@ -2,6 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import { render, screen } from '@testing-library/react';
|
|
3
3
|
import { Wizard, WizardStepFunctionType, WizardStep } from '../Wizard';
|
|
4
4
|
import { DrawerPanelContent, DrawerColorVariant, DrawerHead } from '../../Drawer';
|
|
5
|
+
import userEvent from '@testing-library/user-event';
|
|
5
6
|
|
|
6
7
|
describe('Wizard', () => {
|
|
7
8
|
test('Wizard should match snapshot', () => {
|
|
@@ -222,3 +223,94 @@ describe('Wizard', () => {
|
|
|
222
223
|
expect(main).toHaveAttribute('aria-labelledby', 'main-aria-labelledby');
|
|
223
224
|
});
|
|
224
225
|
});
|
|
226
|
+
|
|
227
|
+
test('wiz with disabled steps', () => {
|
|
228
|
+
const steps: WizardStep[] = [
|
|
229
|
+
{ name: 'A', component: <p>Step 1</p>},
|
|
230
|
+
{ name: 'B', component: <p>Step 2</p>, isDisabled: true },
|
|
231
|
+
{ name: 'C', component: <p>Step 3</p>},
|
|
232
|
+
{ name: 'E', component: <p>Step 4</p>, isDisabled: true },
|
|
233
|
+
{ name: 'G', component: <p>Step 5</p> },
|
|
234
|
+
|
|
235
|
+
];
|
|
236
|
+
|
|
237
|
+
render(
|
|
238
|
+
<Wizard
|
|
239
|
+
navAriaLabel="nav aria-label"
|
|
240
|
+
description="This wizard step is disabled"
|
|
241
|
+
steps={steps}
|
|
242
|
+
/>
|
|
243
|
+
);
|
|
244
|
+
|
|
245
|
+
expect(screen.getByRole('button',{ name: "B" })).toBeDisabled();
|
|
246
|
+
expect(screen.getByRole('button',{ name: "E" })).toBeDisabled();
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
test('wiz skip the step disabled when press the next/back button', () => {
|
|
250
|
+
const steps: WizardStep[] = [
|
|
251
|
+
{ name: 'A', component: <p>Step 1</p>},
|
|
252
|
+
{ name: 'B', component: <p>Step 2</p>, isDisabled: true },
|
|
253
|
+
{ name: 'C', component: <p>Step 3</p>},
|
|
254
|
+
|
|
255
|
+
];
|
|
256
|
+
|
|
257
|
+
render(
|
|
258
|
+
<Wizard
|
|
259
|
+
navAriaLabel="nav aria-label"
|
|
260
|
+
description="This wizard step is disabled"
|
|
261
|
+
steps={steps}
|
|
262
|
+
/>
|
|
263
|
+
);
|
|
264
|
+
|
|
265
|
+
userEvent.click(screen.getByRole('button', { name: 'Next' }));
|
|
266
|
+
expect(screen.getByRole('button',{ name: "C" })).toHaveClass('pf-m-current')
|
|
267
|
+
|
|
268
|
+
userEvent.click(screen.getByRole('button', { name: 'Back' }));
|
|
269
|
+
expect(screen.getByRole('button',{ name: "A" })).toHaveClass('pf-m-current')
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
test('wiz skip the step when click on the nav item disabled', () => {
|
|
273
|
+
const steps: WizardStep[] = [
|
|
274
|
+
{ name: 'A', component: <p>Step 1</p>},
|
|
275
|
+
{ name: 'B', component: <p>Step 2</p>, isDisabled: true },
|
|
276
|
+
{ name: 'C', component: <p>Step 3</p>}
|
|
277
|
+
];
|
|
278
|
+
|
|
279
|
+
render(
|
|
280
|
+
<Wizard
|
|
281
|
+
navAriaLabel="nav aria-label"
|
|
282
|
+
description="This wizard step is disabled"
|
|
283
|
+
steps={steps}
|
|
284
|
+
/>
|
|
285
|
+
);
|
|
286
|
+
|
|
287
|
+
const navItemButton = screen.getByRole('button',{ name: "B" })
|
|
288
|
+
const navItemButtonSelected = screen.getByRole('button',{ name: "A" })
|
|
289
|
+
|
|
290
|
+
userEvent.click(navItemButton);
|
|
291
|
+
|
|
292
|
+
expect(navItemButton).not.toHaveClass('pf-m-current')
|
|
293
|
+
expect(navItemButtonSelected).toHaveClass('pf-m-current')
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
test('wiz with disable sub step', () => {
|
|
297
|
+
const steps: WizardStep[] = [
|
|
298
|
+
{
|
|
299
|
+
name: 'A',
|
|
300
|
+
steps: [
|
|
301
|
+
{ name: 'A-1', component: <p>Substep A content</p> },
|
|
302
|
+
{ name: 'A-2', component: <p>Substep B content</p>, isDisabled: true }
|
|
303
|
+
]
|
|
304
|
+
},
|
|
305
|
+
];
|
|
306
|
+
|
|
307
|
+
render(
|
|
308
|
+
<Wizard
|
|
309
|
+
navAriaLabel="nav aria-label"
|
|
310
|
+
description="This wizard step is disabled"
|
|
311
|
+
steps={steps}
|
|
312
|
+
/>
|
|
313
|
+
);
|
|
314
|
+
|
|
315
|
+
expect(screen.getByRole('button',{ name: "A-2" })).toBeDisabled();
|
|
316
|
+
});
|
|
@@ -40,6 +40,31 @@ class SimpleWizard extends React.Component {
|
|
|
40
40
|
}
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
+
### Basic with disabled steps
|
|
44
|
+
|
|
45
|
+
```js
|
|
46
|
+
import React from 'react';
|
|
47
|
+
import { Button, Wizard } from '@patternfly/react-core';
|
|
48
|
+
|
|
49
|
+
class SimpleWizard extends React.Component {
|
|
50
|
+
constructor(props) {
|
|
51
|
+
super(props);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
render() {
|
|
55
|
+
const steps = [
|
|
56
|
+
{ name: 'First step', component: <p>Step 1 content</p> },
|
|
57
|
+
{ name: 'Second step', component: <p>Step 2 content</p>, isDisabled: true},
|
|
58
|
+
{ name: 'Third step', component: <p>Step 3 content</p> },
|
|
59
|
+
{ name: 'Fourth step', component: <p>Step 4 content</p>, isDisabled: true },
|
|
60
|
+
{ name: 'Review', component: <p>Review step content</p>, nextButtonText: 'Finish' }
|
|
61
|
+
];
|
|
62
|
+
const title = 'Basic wizard';
|
|
63
|
+
return <Wizard navAriaLabel={`${title} steps`} mainAriaLabel={`${title} content`} steps={steps} height={400} />;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
43
68
|
### Anchors for nav items
|
|
44
69
|
|
|
45
70
|
```js
|
package/src/helpers/OUIA/ouia.ts
CHANGED
|
@@ -62,10 +62,8 @@ export const useOUIAProps = (componentType: string, id?: OuiaId, ouiaSafe: boole
|
|
|
62
62
|
* @param {string} variant Optional variant to add to the generated ID
|
|
63
63
|
*/
|
|
64
64
|
export const useOUIAId = (componentType: string, id?: OuiaId, variant?: string) => {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
return useMemo(() => getDefaultOUIAId(componentType, variant), [componentType, variant]);
|
|
65
|
+
const defaultOUIAId = useMemo(() => getDefaultOUIAId(componentType, variant), [componentType, variant]);
|
|
66
|
+
return id ?? defaultOUIAId;
|
|
69
67
|
};
|
|
70
68
|
|
|
71
69
|
/**
|