diff --git a/packages/patternfly-3/patternfly-react/src/components/Wizard/Patterns/StatefulWizardPattern.js b/packages/patternfly-3/patternfly-react/src/components/Wizard/Patterns/StatefulWizardPattern.js index 76782d1ef60..fd84d442570 100644 --- a/packages/patternfly-3/patternfly-react/src/components/Wizard/Patterns/StatefulWizardPattern.js +++ b/packages/patternfly-3/patternfly-react/src/components/Wizard/Patterns/StatefulWizardPattern.js @@ -36,13 +36,14 @@ class StatefulWizardPattern extends React.Component { }; render() { - const { shouldDisableNextStep, ...otherProps } = this.props; + const { shouldDisableNextStep, shouldDisablePreviousStep, ...otherProps } = this.props; const { activeStepIndex } = this.state; // NOTE: the steps array is passed down with ...otherProps, including any shouldPreventEnter or shouldPreventExit functions inside it. // These functions are for StatefulWizardPattern only and should not be used in WizardPattern despite being passed down here. return ( activeStepIndex; - return preventExitActive || preventEnterTarget || (nextStepClicked && nextStepDisabled); + return preventExitActive || preventEnterTarget || nextStepClicked ? nextStepDisabled : previousStepDisabled; }; const activeStepStr = (activeStepIndex + 1).toString(); - const prevStepUnreachable = onFirstStep || activeStep.preventExit || getPrevStep().preventEnter; + const prevStepUnreachable = + previousStepDisabled || onFirstStep || activeStep.preventExit || getPrevStep().preventEnter; // nextStepUnreachable is still true onFinalStep, because the Next button turns into a Close button const nextStepUnreachable = nextStepDisabled || activeStep.isInvalid || activeStep.preventExit || getNextStep().preventEnter; @@ -152,6 +154,7 @@ WizardPattern.propTypes = { closeText: PropTypes.string, steps: PropTypes.arrayOf(PropTypes.shape(wizardStepShape)), nextStepDisabled: PropTypes.bool, + previousStepDisabled: PropTypes.bool, stepButtonsDisabled: PropTypes.bool, nextButtonRef: PropTypes.func, bodyHeader: PropTypes.node, @@ -175,6 +178,7 @@ WizardPattern.defaultProps = { closeText: 'Close', steps: [], nextStepDisabled: false, + previousStepDisabled: false, stepButtonsDisabled: false, nextButtonRef: noop, bodyHeader: null, diff --git a/packages/patternfly-3/patternfly-react/src/components/Wizard/Wizard.test.js b/packages/patternfly-3/patternfly-react/src/components/Wizard/Wizard.test.js index 3dd63bef18f..76cb8b503b8 100644 --- a/packages/patternfly-3/patternfly-react/src/components/Wizard/Wizard.test.js +++ b/packages/patternfly-3/patternfly-react/src/components/Wizard/Wizard.test.js @@ -312,6 +312,7 @@ const testStatefulWizardPattern = props => { onExited={onExited} title="Wizard Pattern Stateful Example" shouldDisableNextStep={() => false} + shouldDisablePreviousStep={() => false} shouldPreventStepChange={() => false} steps={[ { title: 'General', render: () =>

General

}, @@ -378,6 +379,28 @@ const testDisableNextStepWizard = props => { ); }; +const testDisablePreviousStepWizard = props => { + const onHide = jest.fn(); + const onExited = jest.fn(); + const onStepChanged = jest.fn(); + return ( + true} + steps={[ + { title: '1', render: () =>

1

}, + { title: '2', render: () =>

2

}, + { title: '3', render: () =>

3

} + ]} + {...props} + /> + ); +}; + test('Wizard Stateful with shouldDisableNextStep should disable next step', () => { const component = mount(testDisableNextStepWizard()); expect( @@ -387,3 +410,18 @@ test('Wizard Stateful with shouldDisableNextStep should disable next step', () = .getDOMNode().disabled ).toBe(true); }); + +test('Wizard Stateful with shouldDisablePreviousStep should disable previous step', () => { + const component = mount(testDisablePreviousStepWizard()); + component + .find('.wizard-pf-footer .btn') + .at(2) + .simulate('click'); + expect(component.exists('.step2')).toEqual(true); + expect( + component + .find('.wizard-pf-footer .btn') + .at(1) + .getDOMNode().disabled + ).toBe(true); +}); diff --git a/packages/patternfly-3/patternfly-react/src/components/Wizard/__snapshots__/Wizard.test.js.snap b/packages/patternfly-3/patternfly-react/src/components/Wizard/__snapshots__/Wizard.test.js.snap index 222b3b10584..b45bd936156 100644 --- a/packages/patternfly-3/patternfly-react/src/components/Wizard/__snapshots__/Wizard.test.js.snap +++ b/packages/patternfly-3/patternfly-react/src/components/Wizard/__snapshots__/Wizard.test.js.snap @@ -109,6 +109,7 @@ exports[`Wizard Stateful Pattern renders properly: Wizard stateful pattern snaps onHide={[MockFunction]} onNext={[Function]} onStepChanged={[Function]} + previousStepDisabled={false} show={true} stepButtonsDisabled={false} steps={