Command Palette

Search for a command to run...

Docs
FAQ Scroll Accordion

FAQ Scroll Accordion

A scroll-triggered FAQ accordion component with smooth GSAP animations and auto-expanding items

Loading...

Installation

Usage

import FAQScrollAccordion from "@/components/ruixen/faq-scroll-accordion";
 
const faqData = [
  {
    id: 1,
    question: "What is Next.js?",
    answer:
      "Next.js is a React framework for building fast and scalable web applications.",
    icon: "πŸš€",
    iconPosition: "left",
  },
  {
    id: 2,
    question: "Does it support TypeScript?",
    answer: "Yes, Next.js has built-in support for TypeScript.",
    icon: "πŸ“",
    iconPosition: "right",
  },
];
 
export default function MyFAQ() {
  return <FAQScrollAccordion data={faqData} />;
}

Props

PropTypeDefaultDescription
dataFAQItem[]defaultDataArray of FAQ items to display
classNamestring-Additional CSS classes for the container
questionClassNamestring-Additional CSS classes for question styling
answerClassNamestring-Additional CSS classes for answer styling

FAQ Item Structure

Each FAQ item should have the following structure:

interface FAQItem {
  id: number; // Unique identifier for the FAQ item
  question: string; // The question text
  answer: string; // The answer text
  icon?: string; // Optional icon (emoji or text)
  iconPosition?: "left" | "right"; // Position of the icon
}

Features

  • Scroll-Triggered Animation: Uses GSAP ScrollTrigger to automatically expand items as you scroll
  • Smooth Animations: Powered by Framer Motion for smooth expand/collapse transitions
  • Interactive: Click to manually expand/collapse items
  • Customizable Icons: Add optional icons with left or right positioning
  • Responsive Design: Adapts to different screen sizes
  • Accessible: Built on Radix UI Accordion for proper accessibility
  • Dark Mode: Supports both light and dark themes

Examples

Basic Usage

<FAQScrollAccordion />

With Custom Data

const customFAQ = [
  {
    id: 1,
    question: "How does scroll triggering work?",
    answer:
      "The component uses GSAP ScrollTrigger to automatically expand FAQ items as you scroll through the page.",
    icon: "⚑",
    iconPosition: "left",
  },
  {
    id: 2,
    question: "Can I customize the styling?",
    answer:
      "Yes, you can use the className props to customize the appearance of questions and answers.",
    icon: "🎨",
    iconPosition: "right",
  },
];
 
<FAQScrollAccordion data={customFAQ} />;

With Custom Styling

<FAQScrollAccordion
  data={faqData}
  className="bg-gradient-to-b from-blue-50 to-white"
  questionClassName="bg-blue-100 hover:bg-blue-200"
  answerClassName="bg-green-400 text-white"
/>

Without Icons

const simpleData = [
  {
    id: 1,
    question: "Simple question without icon",
    answer: "This FAQ item doesn't have an icon.",
  },
];
 
<FAQScrollAccordion data={simpleData} />;

Animation Details

The component creates a scroll-triggered timeline that:

  1. Pins the container during scroll
  2. Auto-expands items sequentially as you scroll
  3. Smooth transitions using Framer Motion
  4. Manual interaction remains available at any time

The scroll trigger is configured with:

  • scrub: 0.3 for smooth scroll-linked animation
  • Dynamic end point based on number of FAQ items
  • Automatic cleanup on component unmount

Dependencies

  • framer-motion - For smooth animations
  • @radix-ui/react-accordion - For accessible accordion functionality
  • lucide-react - For plus/minus icons
  • gsap - For scroll-triggered animations
  • @gsap/react - React integration for GSAP