From 5c866c2ca0b49ab0819ad9d542e32a4e31a4b152 Mon Sep 17 00:00:00 2001 From: Rastislav Wagner Date: Fri, 10 Aug 2018 12:36:24 +0200 Subject: [PATCH] Allow disabling back button in Wizard.Pattern. Fixes #527 --- .../Wizard/Patterns/WizardPattern.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/patternfly-react/src/components/Wizard/Patterns/WizardPattern.js b/packages/patternfly-react/src/components/Wizard/Patterns/WizardPattern.js index b1300eb2d59..e013f21f846 100644 --- a/packages/patternfly-react/src/components/Wizard/Patterns/WizardPattern.js +++ b/packages/patternfly-react/src/components/Wizard/Patterns/WizardPattern.js @@ -14,6 +14,7 @@ const WizardPattern = ({ onNext, onBack, nextStepDisabled, + backStepDisabled, title, loadingTitle, loadingMessage, @@ -80,19 +81,20 @@ const WizardPattern = ({ const preventEnterTarget = targetStep.preventEnter || (stepBeforeTarget && stepBeforeTarget.isInvalid); - const nextStepClicked = newStepIndex === activeStepIndex + 1; + const nextStepClicked = newStepIndex > activeStepIndex; - return ( - preventExitActive || - preventEnterTarget || - (nextStepClicked && nextStepDisabled) - ); + return preventExitActive || preventEnterTarget || nextStepClicked + ? nextStepDisabled + : backStepDisabled; }; const activeStepStr = (activeStepIndex + 1).toString(); const prevStepUnreachable = - onFirstStep || activeStep.preventExit || getPrevStep().preventEnter; + backStepDisabled || + onFirstStep || + activeStep.preventExit || + getPrevStep().preventEnter; // nextStepUnreachable is still true onFinalStep, because the Next button turns into a Close button const nextStepUnreachable = nextStepDisabled || @@ -168,6 +170,7 @@ WizardPattern.propTypes = { closeText: PropTypes.string, steps: PropTypes.arrayOf(PropTypes.shape(wizardStepShape)), nextStepDisabled: PropTypes.bool, + backStepDisabled: PropTypes.bool, stepButtonsDisabled: PropTypes.bool, nextButtonRef: PropTypes.func, bodyHeader: PropTypes.node, @@ -191,6 +194,7 @@ WizardPattern.defaultProps = { closeText: 'Close', steps: [], nextStepDisabled: false, + backStepDisabled: false, stepButtonsDisabled: false, nextButtonRef: noop, bodyHeader: null,