damianricobelli / stepperize

A library for creating step-by-step workflows in your apps
https://stepperize.vercel.app
917 stars 40 forks source link

React Hook Form back button doesn't work if you add more than 3 steps #75

Open scotthez opened 1 month ago

scotthez commented 1 month ago

Describe the bug Looking at the react hook form examples, if you add another step within that example the back button doesnt work within the newly created steps.

To Reproduce Steps to reproduce the behavior:

  1. Add a new step within the existing example
  2. Navigate to the new step, and then try the back button.

Expected behavior Should go to previous step

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context Add any other context about the problem here.

wdamianw commented 1 week ago

I had the same issue. I solved it by adding e.preventDefault() to the button that triggers the stepper.prev() action:

<Button
    className="w-36"
    variant="outline"
    onClick={(e) => {
        e.preventDefault();
        stepper.prev();
    }}
    disabled={stepper.isFirst}
>
ecbakas commented 1 week ago

You just have to add the type="button" attribute for the "prev" button.

Ekran Resmi 2024-11-06 22 23 24