Ruixen Pro is now live.50+ premium components, templates, blocks, and lifetime updates.

Command Palette

Search for a command to run...

Docs
FAQ Scroll Accordion

FAQ Scroll Accordion

Self-contained scroll cascade — items auto-open as they reach the container's center zone

Installation

Usage

import { FAQScrollAccordion } from "@/components/ruixen/faq-scroll-accordion";
import type { FAQItem } from "@/components/ruixen/faq-scroll-accordion";
 
const items: FAQItem[] = [
  {
    question: "What is Ruixen UI?",
    answer: "A curated collection of production-ready components.",
  },
  {
    question: "Is it open-source?",
    answer: "Yes, fully open-source under the MIT license.",
  },
];
 
export default function MyFAQ() {
  return <FAQScrollAccordion items={items} />;
}

Props

PropTypeDefaultDescription
titlestring"Frequently asked questions"Section heading
subtitlestring"Everything you need to know."Subtitle below heading
itemsFAQItem[]Built-in defaultsArray of FAQ items
scrollDrivenbooleantrueEnable scroll-driven auto-open
defaultActivenumber | null0Initially open item index
classNamestringAdditional classes on root section

FAQItem

interface FAQItem {
  question: string;
  answer: string;
}

Self-Contained Scroll Container

The component creates its own scrollable container (max-h-80, overflow-y-auto) with the IntersectionObserver scoped to it via root: scrollContainer. This means:

  • Page scroll has zero effect on which item opens — only scrolling within the component's container triggers changes
  • Works in iframes and previews — the container IS the scroll context
  • Gradient masks at top and bottom (5%) indicate scrollable content
  • Hidden scrollbar for clean aesthetics (scrollbar-width: none)

The center detection zone is the middle 20% of the container (rootMargin: "-40% 0px -40% 0px"). An item must reach this zone to auto-open — slight scrolling won't trigger changes.

Click Behavior

Clicking an item:

  1. Opens/closes it immediately
  2. Smooth-scrolls the container to center the clicked item
  3. Pauses scroll-driven behavior for 3 seconds so the observer doesn't override user intent

Animation Details

  • Grid expandgrid-template-rows: 0fr → 1fr for smooth height animation (450ms, expo deceleration)
  • Answer choreography — text fades in + slides up with 100ms delay after container opens
  • Chevron rotation — inline SVG rotates 180deg with expo easing
  • Close is faster — text fades in 150ms, container collapses in 300ms

Features

  • Zero dependencies — no GSAP, no framer-motion, no lucide-react
  • Self-contained scroll context — immune to page scroll
  • Click-to-center with scroll pause
  • Proper TypeScript interfaces
  • Theme-aware via CSS custom properties
  • Accessible — semantic buttons, keyboard navigable