MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Mini Project: Dynamic FAQ Accordion0%
Study Materials
React.js for BeginnersProgress 0%
1.1Why React and Single-Page Architecture1.2Setting Up Modern React with Vite1.3React Project Directory Structure and Entry Points1.4Virtual DOM and React Render Cycle Explained
10.1Mini Project: Interactive Counter with Step Controls10.2Mini Project: Dynamic FAQ Accordion10.3Mini Project: Real-Time Character Counter and Text Utility
HomeTutorialsReact.js for BeginnersMini Project: Dynamic FAQ Accordion
Mini Project: Real-Time Character Counter and Text Utility

Mini Project: Dynamic FAQ Accordion

Beginner12 min read•Updated: 2026-11-18•By Er. Sumit Kumar (MSK Institute)
Study MaterialsCheatsheet

1. Project Overview & Requirements

Accordions are ubiquitous UI patterns in modern web engineering, seen on landing pages, documentation portals, and knowledge bases.

In this project, we will engineer a Dynamic FAQ Accordion with support for:

  1. 1
    Collapsible Panels: Expanding and collapsing individual questions smoothly.
  2. 2
    Single-Open vs Multi-Open Mode: A toggle allowing either one question open at a time (standard accordion) or multiple questions open simultaneously.
  3. 3
    Category Filtering: Filter questions by topic (General, Curriculum, Certification).
  4. 4
    Keyboard Accessibility: Semantic markup and ARIA attributes (aria-expanded, aria-controls).
1┌────────────────────────────────────────────────────────┐
2│ Frequently Asked Questions │
3│ │
4│ Mode: [x] Allow multiple sections open │
5│ │
6│ [▼] What prerequisites are required for React? │
7│ └─ Solid foundation in HTML, CSS, and modern ES6 │
8│ JavaScript (arrow functions, destructuring). │
9│ │
10│ [►] Is job placement assistance provided? │
11│ [►] Can I access the lab environment on mobile? │
12└────────────────────────────────────────────────────────┘

2. Component Implementation

1import React, { useState } from 'react';
2 
3const FAQ_DATA = [
4 {
5 id: 'faq-1',
6 question: 'What prerequisites are required before starting React?',
7 answer: 'You should be comfortable with HTML5, modern CSS layouts (Flexbox/Grid), and ES6+ JavaScript concepts including let/const, arrow functions, destructuring, and array methods (map/filter).'
8 },
9 {
10 id: 'faq-2',
11 question: 'Why should I learn Vite instead of Create React App?',
12 answer: 'Vite leverages native browser ES Modules and esbuild, resulting in near-instant local server start times, lightning-fast Hot Module Replacement, and optimized production bundles.'
13 },
14 {
15 id: 'faq-3',
16 question: 'Does MSK Institute provide industry-recognized certificates?',
17 answer: 'Yes! Upon completing the comprehensive capstone projects and passing the graded quizzes, students receive a cryptographically verifiable MSK Institute Certificate of Completion.'
18 }
19];
20 
21export default function FaqAccordion() {
22 // Store an array of active open IDs (supports both single and multi mode)
23 const [openIds, setOpenIds] = useState(['faq-1']);
24 const [allowMultiple, setAllowMultiple] = useState(false);
25 
26 const toggleItem = (id) => {
27 if (allowMultiple) {
28 // Multi-open mode: toggle id in array
29 setOpenIds((prev) =>
30 prev.includes(id) ? prev.filter((item) => item !== id) : [...prev, id]
31 );
32 } else {
33 // Single-open mode: open clicked item, or close if already open
34 setOpenIds((prev) => (prev.includes(id) ? [] : [id]));
35 }
36 };
37 
38 return (
39 <div className="faq-wrapper">
40 <header className="faq-header">
41 <h2>Frequently Asked Questions</h2>
42
43 {/* Toggle Mode Option */}
44 <label className="toggle-label">
45 <input
46 type="checkbox"
47 checked={allowMultiple}
48 onChange={(e) => {
49 setAllowMultiple(e.target.checked);
50 // Reset to at most 1 item when switching back to single mode
51 if (!e.target.checked && openIds.length > 1) {
52 setOpenIds(openIds.slice(0, 1));
53 }
54 }}
55 />
56 Allow multiple sections open at once
57 </label>
58 </header>
59 
60 <div className="accordion-list">
61 {FAQ_DATA.map((item) => {
62 const isOpen = openIds.includes(item.id);
63 
64 return (
65 <div key={item.id} className={`accordion-item ${isOpen ? 'active' : ''}`}>
66 {/* Header Button */}
67 <button
68 type="button"
69 className="accordion-trigger"
70 onClick={() => toggleItem(item.id)}
71 aria-expanded={isOpen}
72 aria-controls={`panel-${item.id}`}
73 >
74 <span className="accordion-title">{item.question}</span>
75 <span className="accordion-icon">{isOpen ? '−' : '+'}</span>
76 </button>
77 
78 {/* Collapsible Panel */}
79 {isOpen && (
80 <div
81 id={`panel-${item.id}`}
82 className="accordion-panel"
83 role="region"
84 >
85 <p>{item.answer}</p>
86 </div>
87 )}
88 </div>
89 );
90 })}
91 </div>
92 </div>
93 );
94}

3. Accessibility & Architectural Highlights

  1. 1
    ARIA Attributes: aria-expanded={isOpen} informs screen readers whether the dropdown is currently open.
  2. 2
    Unified Data Structure: Storing openIds as an array cleanly supports both single-item ([id]) and multi-item ([id1, id2]) expansion modes without duplicate state logic.
  3. 3
    Conditional DOM Mounting: {isOpen && <div ...>} unmounts the panel when closed, keeping the DOM lightweight.

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
What ARIA attribute should be added to an accordion trigger button to communicate its expansion state to assistive technologies?
Question 2
How does the accordion component support toggling an item in multi-open mode?
Question 3
What happens when the user unchecks "Allow multiple sections open at once" while 3 sections are open?
Question 4
Why is type="button" explicitly added to the <button> trigger inside the accordion?
Question 5
Why is item.id used as the key instead of the index in the accordion list?
Next Lesson

Mini Project: Real-Time Character Counter and Text Utility

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Mini Project: Interactive Counter with Step ControlsMini Project: Real-Time Character Counter and Text Utility

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master React.js for Beginners with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext