Overview
Many complex user flows, such as onboarding, multi-part forms, or checkout processes, benefit immensely from a "Stepper Wizard" UI pattern. This pattern guides users through a series of distinct steps, clearly indicating progress and allowing focused input at each stage. Building a robust and intuitive Stepper component is crucial for enhancing user experience in such applications, providing clear visual feedback and enabling smooth navigation.
What you need to do / Task
Your primary task is to implement a reusable Stepper React component that visualizes a sequence of steps and allows users to navigate through them.
- Component Structure: Create a
Stepper component that accepts an array of Step objects as props. Each Step object should have at least a key (unique identifier) and a title.
- Step Rendering: Display each step with its sequential number and descriptive title. Ensure there's clear visual differentiation between the current active step, completed steps (those the user has navigated past), and upcoming/incomplete steps.
- Navigation: Implement "Next" and "Previous" buttons to facilitate movement between steps.
- The "Next" button should advance to the subsequent step.
- The "Previous" button should move to the prior step.
- These navigation buttons must be appropriately disabled when the user is on the first step ("Previous" disabled) or the last step ("Next" disabled).
- Step Completion (Simplified): For this exercise, a step is considered "completed" once the user navigates past it. When a user moves from step N to step N+1, step N becomes visually marked as "completed". If they navigate back to step N, it should retain its "completed" status.
- State Management: Manage the current active step's index and the set of completed steps internally within the
Stepper component's state.
UI/UX expectations
- Layout: Steps should be displayed horizontally, typically with a numerical indicator (e.g., a circle) and its corresponding title positioned below or beside it. Connectors between steps are encouraged to show progression.
- Visual Cues:
- Current Step: Must be clearly highlighted (e.g., distinct background/border color for the number, bolded text for the title).
- Completed Steps: Should be visually distinct from both current and upcoming steps (e.g., a checkmark icon or a different, muted color scheme).
- Upcoming Steps: Should have a default, neutral styling, indicating they are yet to be visited.
- Navigation Buttons: Position "Previous" and "Next" buttons clearly below the step indicators, ensuring they are easily discoverable and interactable.
- Accessibility:
- Utilize appropriate semantic HTML elements for the stepper structure.
- Ensure the current active step is correctly identified for screen readers (e.g., using
aria-current="step").
- Provide
aria-label or similar attributes for interactive elements where beneficial for clarity and context.
Acceptance criteria
- The
Stepper component correctly renders all provided steps, displaying their sequential numbers and titles.
- The currently active step is visually highlighted according to UI/UX expectations.
- Clicking the "Next" button successfully advances the active step, and the UI updates to reflect this change.
- Clicking the "Previous" button successfully moves to the prior active step, with the UI updating accordingly.
- The "Next" button is disabled when the active step is the last step in the sequence.
- The "Previous" button is disabled when the active step is the first step in the sequence.
- Steps that have been navigated past are visually marked as "completed" and retain this status upon returning to a previous step.
- Basic accessibility attributes, such as
aria-current="step" for the active step, are correctly implemented.