Frontend School

Dynamic FAQ Accordion with Search & Accessibility

Machine Coding
hard

Dynamic FAQ Accordion with Search & Accessibility

Hard
React
TypeScript
Accessibility
Accordion
Search
UI

Overview

Phonepe's support portal requires a robust and accessible FAQ section to help users quickly find answers to common queries. This section needs to be dynamic, allowing for easy updates and an intuitive user experience. Your task is to build a highly interactive and performant accordion component that supports search functionality and adheres to modern accessibility standards.

What you need to do / Task

  1. Implement a FAQAccordion component:
    • It should accept an array of FAQ items, each with a question (string) and answer (string).
    • Each item should be expandable/collapsible.
    • By default, only one FAQ item can be open at a time (single-select mode).
    • Add a prop allowMultipleOpen (boolean, default false) to enable multi-select mode, where multiple FAQ items can be open simultaneously.
  2. Integrate Search Functionality:
    • Include an input field above the accordion.
    • As the user types, filter the displayed FAQ items. Filtering should match both question and answer (case-insensitive).
    • If a filtered item's question or answer matches the search query, it should be displayed. If no query, all items are displayed.
  3. Ensure Accessibility (A11y):
    • Implement correct ARIA attributes for accordion components (e.g., aria-expanded, aria-controls, aria-labelledby, role="region", hidden).
    • Ensure robust keyboard navigation:
      • Tab key should move focus between accordion headers.
      • Space or Enter key on a header should toggle its expanded state.
      • Up/Down arrow keys should navigate focus between accordion headers within the accordion.
      • Home and End keys should move focus to the first and last accordion headers, respectively.
  4. Basic Styling & Animations:
    • Apply minimal CSS to make the accordion visually distinct and usable.
    • Include a smooth transition for the expansion/collapse of accordion content height.

UI/UX expectations

  • The search input should be prominently placed above the accordion.
  • Each accordion item should have a clear header (question) and a collapsible content area (answer).
  • When an item is open, its header should visually indicate the open state (e.g., a rotated icon, different background).
  • The content area should smoothly animate its height when expanding/collapsing.
  • Focus styles should be visible for interactive elements, especially accordion headers.

Acceptance criteria

  • The FAQAccordion component renders all provided FAQ items initially.
  • Clicking an item's header toggles its expanded/collapsed state.
  • In default mode, opening one item collapses any previously open item.
  • With allowMultipleOpen prop, multiple items can be open simultaneously.
  • Typing in the search box filters FAQ items based on question or answer content (case-insensitive).
  • Clearing the search box displays all FAQ items again.
  • Accordion headers have aria-expanded and aria-controls attributes correctly applied and updated.
  • Accordion content has id, role="region", and aria-labelledby attributes correctly applied, and hidden attribute toggles with state.
  • Keyboard navigation (Tab, Enter, Space, Up/Down arrows, Home, End) functions as specified, moving focus between headers and toggling state.
  • Expansion/collapse transitions are smooth and visually appealing.

Constraints

Constraints & assumptions

  • The component will be built using React (with TypeScript).
  • No external UI libraries (e.g., Material-UI, Ant Design) are allowed; build from scratch using native HTML elements and CSS.
  • The maximum number of FAQ items will be around 100-200. Performance should be considered, but heavy virtualization is not expected.
  • Assume a modern browser environment.
  • Styling can be minimal but functional and clear. Focus primarily on behavior, logic, and accessibility.

What interviewers evaluate

  • Component Design & Architecture: How well the FAQAccordion component is structured, its props, state management, and separation of concerns.
  • Core Functionality: Correct implementation of expand/collapse logic, single/multi-select modes, and robust search filtering.
  • Accessibility (A11y): Proper use of ARIA attributes and comprehensive keyboard navigation.
  • Code Quality: Readability, maintainability, effective use of TypeScript, and efficient rendering practices.

Loading editor...