Frontend School

Build a Dynamic Accordion Component for Groww FAQs

Machine Coding
medium

Build a Dynamic Accordion Component for Groww FAQs

Medium
React
UI Components
Accordion
Accessibility
State Management

Overview

Groww aims to provide an excellent user experience, and a key part of that is easily accessible information. Our support section requires a robust and user-friendly FAQ component. This problem focuses on building a reusable Accordion component to display frequently asked questions and their answers, ensuring a smooth and intuitive interaction for our users. This task will test your ability to design a modular UI component, manage its state effectively, and incorporate essential accessibility features.

What you need to do / Task

Your primary goal is to implement a Accordion component in React that meets the following requirements:

  1. Component Creation: Develop a reusable Accordion component that accepts an array of data items.
  2. Data Structure: Each item in the array will have an id, title, and content (string).
  3. Single-Item Expansion: The accordion must support single-select behavior, meaning only one item can be expanded (open) at any given time. Expanding a new item should automatically collapse the previously open one.
  4. State Management: Implement proper state management within the Accordion component to track which item is currently expanded.
  5. Toggle Functionality: Clicking an item's title should toggle its content visibility (expand/collapse).
  6. Accessibility: Integrate basic accessibility features to ensure the component is usable by everyone, including keyboard users and those using assistive technologies.

UI/UX expectations

  • Each accordion item should clearly display its title and have a collapsible content area.
  • Clicking an item's title should smoothly expand its content while collapsing any other currently open item.
  • A visual indicator (e.g., an arrow icon or a plus/minus sign) should be present next to the title, changing its orientation or appearance to reflect the expanded/collapsed state of the item.
  • Basic styling should ensure readability, clear visual separation between items, and a clean overall look.
  • Keyboard Navigation: Users should be able to navigate between accordion item titles using the Tab key. Pressing Enter or Space on a focused title should toggle its expanded state.

Acceptance criteria

  • [ ] The Accordion component renders correctly with the provided faqData.
  • [ ] Clicking an item's title toggles the visibility of its corresponding content.
  • [ ] Only one accordion item can be open at any given time (single-select behavior is enforced).
  • [ ] Clicking an already open item's title collapses its content.
  • [ ] A visual indicator (e.g., an arrow) clearly changes its state (e.g., rotates) to signify if an item is expanded or collapsed.
  • [ ] Keyboard navigation is fully functional: Tab moves focus between accordion buttons, and Enter/Space toggles the focused item.
  • [ ] Appropriate ARIA attributes (aria-expanded, aria-controls, id, role) are used to convey the component's state and structure to assistive technologies.

Constraints

Constraints & assumptions

  • You must use React for building the component.
  • Do not use any external UI component libraries (e.g., Material UI, Ant Design). All UI elements and styling should be built from scratch.
  • Focus on functional components and React Hooks for state management.
  • The provided faqData structure should be used as input.
  • Assume modern browser support (Chrome, Firefox, Edge).

Out of scope

  • Complex animations for expand/collapse transitions.
  • Dynamic data fetching; assume faqData is available upfront.
  • Support for multiple-item expansion (multi-select accordion).

What interviewers evaluate

  • Component Design & Reusability: How well the Accordion component is structured, its props interface, and its potential for reuse.
  • State Management: Effective and idiomatic use of React hooks (useState, useRef, etc.) to manage component state.
  • Accessibility Implementation: Correct application of ARIA attributes and keyboard navigation for an inclusive user experience.
  • Code Quality: Readability, maintainability, and adherence to best practices in React development.

Loading editor...