Skip to content

Commit

Permalink
Allow disabling back button in Wizard.Pattern. Fixes #527
Browse files Browse the repository at this point in the history
  • Loading branch information
rawagner committed Aug 10, 2018
1 parent 3958558 commit 5c866c2
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const WizardPattern = ({
onNext,
onBack,
nextStepDisabled,
backStepDisabled,
title,
loadingTitle,
loadingMessage,
Expand Down Expand Up @@ -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 ||
Expand Down Expand Up @@ -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,
Expand All @@ -191,6 +194,7 @@ WizardPattern.defaultProps = {
closeText: 'Close',
steps: [],
nextStepDisabled: false,
backStepDisabled: false,
stepButtonsDisabled: false,
nextButtonRef: noop,
bodyHeader: null,
Expand Down

0 comments on commit 5c866c2

Please sign in to comment.