Skip to content

Commit

Permalink
ability to skip a multistep step
Browse files Browse the repository at this point in the history
  • Loading branch information
joepuzzo committed Feb 6, 2023
1 parent 0bebbe4 commit a9d17ad
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 4.40.0 (Feb 6th, 2023)

### Added

- ability to skip a multistep step

## 4.39.3 (January 23rd, 2023)

### Fixed
Expand Down
10 changes: 5 additions & 5 deletions src/hooks/useMultistep.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,19 +185,19 @@ const useMultistep = ({ initialStep, multistepApiRef }) => {
}
};

const next = cb => {
const next = (cb, { skip } = {}) => {
// Get the next step
const nextStep = getNextStep();
if (nextStep) {
// Touch all the fields
formApi.touchAllFields();
if (!skip) formApi.touchAllFields();
// Validate the form
validate();
if (!skip) validate();
// Async validate the form
// We pass in a callback to proceed if we succeed async validation!
asyncValidate(() => proceed(nextStep, cb));
if (!skip) asyncValidate(() => proceed(nextStep, cb));
// Only proceed if we are valid and we are NOT currently async validating
if (getFormState().valid && getFormState().validating === 0) {
if (skip || (getFormState().valid && getFormState().validating === 0)) {
proceed(nextStep, cb);
}
}
Expand Down
4 changes: 4 additions & 0 deletions stories/Multistep/Actions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ const Favorite = () => {
<button type="button" onClick={next}>
Next
</button>
{/* You can do this to skip this step */}
<button type="button" onClick={() => next(null, { skip: true })}>
Skip
</button>
</div>
</Multistep.Step>
);
Expand Down
4 changes: 4 additions & 0 deletions stories/Multistep/Actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ const Favorite = () => {
<button type="button" onClick={next}>
Next
</button>
{/* You can do this to skip this step */}
<button type="button" onClick={() => next(null, { skip: true })}>
Skip
</button>
</div>
</Multistep.Step>
);
Expand Down
3 changes: 3 additions & 0 deletions stories/Multistep/Basic/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ const Info = () => {
<button type="button" onClick={next}>
Next
</button>
{/* <button type="button" onClick={() => next(null, { skip: true })}>
Next
</button> */}
</Multistep.Step>
);
};
Expand Down

0 comments on commit a9d17ad

Please sign in to comment.