Frontend School

Interactive Stepper Wizard Component

Machine Coding
medium

Interactive Stepper Wizard Component

Medium
React
TypeScript
UI Components
State Management
Accessibility

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.

  1. 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.
  2. 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.
  3. 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).
  4. 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.
  5. 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.

Constraints

Constraints & assumptions

  • Environment: Standard web browser environment.
  • Frameworks: React with TypeScript. No other UI component libraries (e.g., Material UI, Ant Design, Chakra UI) are allowed; the solution should be built from scratch.
  • Data: The steps data will be provided as a simple array of objects, each guaranteed to have key: string and title: string. You can assume valid input and do not need to handle malformed data.
  • Styling: Use plain CSS or CSS Modules. No CSS-in-JS libraries (e.g., styled-components, Emotion).
  • Scope: Focus strictly on the UI and client-side state management for the stepper. No persistence, API calls, complex routing integration, or deep validation of step content is required.
  • Time Budget: The problem is designed to be completable within approximately 45 minutes.

Out of scope

  • Complex form validation for content within each individual step.
  • Deep routing integration (e.g., changing the URL path based on the active step).
  • Dynamic addition, removal, or reordering of steps after initial render.
  • Advanced animations or transitions between step changes.
  • Comprehensive keyboard navigation beyond basic button focus and activation.

What interviewers evaluate

  • Component Design: The overall structure, reusability, clear interface, and effective modularity of the Stepper component.
  • State Management: Correct and efficient handling of the active step index and the set of completed steps within the component's state.
  • UI/UX Implementation: Accuracy in rendering, clear visual feedback for different step states (current, completed, upcoming), and robust navigation logic, including correct handling of boundary conditions.
  • Accessibility: Thoughtful inclusion of basic accessibility attributes to ensure the component is usable and understandable for a wider audience, including screen reader users.
  • Code Quality: Readability, maintainability, adherence to best practices, and effective utilization of TypeScript features for type safety.

Loading editor...