A stepper to indicate the user's progress through a multi-step process or form.
tailwind.config.ts
Modify your tailwind.config.ts
as follows:
By using the orientation prop you are able to switch between horizontal (default) and vertical orientations. By default, when in mobile view the Steps component will switch to vertical orientation. You are also able to customize the breakpoint at which the component switches to vertical orientation by using the mobileBreakpoint prop.
The second step is optional and can be skipped by the user.
You can change the style of the stepper by passing the variant prop
Sometimes it is useful to display visual feedback to the user depending on some asynchronous logic. In this case we can use the state prop to display a loading or error indicator with the values of loading | error. This prop can be used globally within the Stepper component or locally in the Step component affected by this state.
If you want to show custom icons instead of the default numerical indicators, you can do so by using the icon prop on the Step component. To change the general check and error icons, we can use the checkIcon
and errorIcon
prop inside the Stepper component
If you would like the stepper to scroll to the active step when it is not in view you can do so using the scrollTracking prop on the Stepper component.
For scroll tracking to make sense, the content of each step should ideally include the buttons that allow the user to move forward or backward in the stepper, since the user should be able to see the content of the active step and not need to scroll to the end of the stepper in order to move forward or backward.
If you want to use the stepper with forms, you can do so by using the useStepper hook to control the component. This example uses the Form component of shadcn and the react-hook-form hooks to create a form with zod for validations. You can also use the component with server actions.
Step 1
Step 1
Step 1
Step 1