Frontend School

React Multi-step Form with State Machine & Validation

Machine Coding
medium

React Multi-step Form with State Machine & Validation

Medium
React
Forms
Validation
State Machine
Multi-step
Accessibility
ui-build
frontend-interview
Machine Coding
take-home

Overview

You're building the registration flow for "VentureConnect", a platform connecting startups with investors. This task involves creating a multi-step form that guides users through submitting their startup's profile. The form must handle state transitions, validate user input at each step, and provide clear navigation. This problem focuses on robust form management, state logic, and user experience in React.

What you need to do / Task

  1. Implement a multi-step form structure with at least three distinct steps.
  2. Each step should have specific input fields with appropriate HTML5 types (e.g., text, email, number, URL, textarea).
  3. Implement client-side validation for each step, preventing progression to the next step if current fields are invalid.
  4. Display clear error messages for invalid inputs.
  5. Allow users to navigate between steps using "Next" and "Previous" buttons.
  6. The "Previous" button should always be enabled except on the first step.
  7. The "Next" button should be disabled if the current step's fields are invalid.
  8. Upon completing the final step, display a summary of all submitted data.
  9. Ensure the form is accessible, including proper labels, input types, and focus management.

UI/UX expectations

  • Layout: The form should be centrally aligned, clearly indicating the current step (e.g., "Step 1 of 3: Company Info").
  • Navigation: "Previous" and "Next" buttons should be clearly visible. The "Next" button should visually indicate its disabled state when validation fails.
  • Feedback: Error messages for invalid fields should appear immediately after a field loses focus or on an attempt to proceed.
  • Accessibility: All form inputs must have associated <label> elements. Navigate with keyboard (Tab, Shift+Tab) should work correctly. Error messages should be programmatically associated with their inputs (e.g., using aria-describedby).

Acceptance criteria

  • [ ] The form renders with the first step visible.
  • [ ] Each step correctly displays its designated input fields.
  • [ ] "Next" button is disabled if required fields on the current step are empty or invalid.
  • [ ] "Next" button enables when all required fields on the current step are valid.
  • [ ] Clicking "Next" (when enabled) transitions the user to the subsequent step.
  • [ ] "Previous" button is disabled on the first step.
  • [ ] Clicking "Previous" (when enabled) transitions the user to the prior step, preserving input data.
  • [ ] Error messages are displayed for invalid inputs.
  • [ ] Upon reaching the final step and clicking "Submit" (or equivalent), a summary of all collected data is shown.
  • [ ] Keyboard navigation (Tab, Shift+Tab) works as expected within the form.
  • [ ] All form fields have visible and programmatically associated labels.

Clarifications

  • Q: What validation rules are required?
    • A: At a minimum, ensure all fields are non-empty. For specific fields: Company Name (text), Founder Email (email format), Funding Goal (number, min 1000), Website URL (URL format), Description (textarea, min 50 chars).
  • Q: Should I use a state management library?
    • A: No, manage form state and step transitions using React's built-in useState and useReducer hooks.
  • Q: Is routing required?
    • A: No, the entire multi-step form should exist within a single component. Step transitions are handled internally, not via URL changes.

Constraints

Constraints & assumptions

  • Stack: React (functional components, hooks).
  • Browser Support: Modern evergreen browsers (Chrome, Firefox, Safari, Edge).
  • Styling: Basic CSS for layout and visual feedback is sufficient. No specific UI library is required.
  • Validation: Client-side validation only. No server-side interaction.
  • Accessibility: Focus on basic keyboard navigation and screen reader compatibility for form elements.

Out of scope

  • Backend integration or API calls.
  • Third-party form libraries (e.g., Formik, React Hook Form).
  • Complex animations or transitions between steps.
  • Saving or persisting form data beyond the current session.
  • Internationalization (i18n).

What graders evaluate

  • Correct implementation of multi-step navigation logic.
  • Robust client-side validation with clear error feedback.
  • Effective use of React state management (e.g., useState, useReducer).
  • Adherence to basic accessibility best practices for forms.
  • Clean, readable, and well-structured code.

Loading editor...