Skip to content
Submitted about 11 hours ago

Accessible multi-step form with React, Tailwind, Vitest & Playwright

react, react-testing-library, playwright, storybook, vitest
P
LVL 4
Berefire•1,042
@berefire
A solution to the Multi-step form challenge

Solution retrospective


What are you most proud of, and what would you do differently next time?

I'm most proud of the architecture and the testing. All form state lives in a single useMultiStepForm hook, and every step is a controlled component, so going back never loses the user's choices, and the summary always calculates prices from the same data.

The plan cards and add-ons use real radio buttons and checkboxes hidden with sr-only, so keyboard navigation and screen reader announcements work natively. Tailwind's has-checked: variant and a custom focus-ring-within utility (:has(:focus-visible)) style the whole card from the hidden input's state.

The project is tested at every level: pure functions (pricing, validation), the hook (renderHook), components and full-flow integration tests (React Testing Library + vitest-axe), and Playwright end-to-end tests on desktop and mobile viewports, with axe checks in a real browser.

Next time I would:

  • Write integration tests earlier. My component tests used mocks, so they passed while the real app had a bug: leftover test data pre-selected two add-ons. The App integration test caught it, but only near the end.
What challenges did you encounter, and how did you overcome them?
  • The mobile navigation bar jumped during step transitions. The bar is position: fixed, and it was inside the animated wrapper. While that wrapper had a transform, it became the bar's containing block instead of the viewport. Moving FormNavigation outside the animated element fixed it.
  • The design's colors fail WCAG AA. Running axe through Playwright showed the cool gray (2.82:1) and the strawberry red (4.03:1) are too light for small text. I kept their hue and saturation and only lowered the lightness in HSL, so they still look like the design's colors but meet the 4.5:1 ratio.
  • A flaky accessibility test in CI. axe sometimes ran while the step was still fading in, so it measured a semi-transparent color. Waiting for document.getAnimations() to finish before running axe made the test reliable.
  • A button with the wrong accessible name. "Change" + a visually hidden " plan" was computed as "Changeplan". An aria-label="Change plan" gives the same name in every browser and screen reader, while still containing the visible text for voice control users.
What specific areas of your project would you like help with?
  1. Color contrast vs. the design. I adjusted two of the design's colors to meet WCAG AA. Would you approach this differently, for example keeping the original colors and making the text larger or bolder?
  2. The fixed mobile navigation bar. I used bottom padding (pb-32) so the content can scroll above the bar, which feels like a magic number. Is there a cleaner layout pattern for a bottom bar on mobile?
  3. Test overlap. Some flows are covered by both React Testing Library integration tests and Playwright. How do you decide what belongs at each level?
  4. Exit animations. Steps animate in but disappear instantly. Is it worth adding a library like Motion for this, or is there a lightweight CSS approach?
Code
Loading...

Please log in to post a comment

Log in

Community feedback

No feedback yet. Be the first to give feedback on Berefire’s solution.

Join our Discord community

Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!

Join our Discord