Staaarter

Topic Rail FAQ

A categorised FAQ whose topic rail is derived from the questions themselves and carries a live count badge per topic. Clicking a topic switches the accordion beside it to that topic's questions and resets which item is expanded back to the first one.

By Staaarter Team
FAQ
Docs
Live preview

Docs

Installation

A real shadcn registry command, not a copy-paste stand-in: it fetches this block plus its badge dependencies and any missing npm packages, and installs them straight into your project.

npx shadcn add https://staaarter.com/r/topic-rail-faq.json

Prefer not to use the CLI? Copy the source from the Code toggle above into src/components/blocks/faq/faq82.tsx instead.

Usage

The file also exports faq82Demo, the exact props behind the preview above. Spread it to get a working section in one line, then replace it with your own data.

import { Faq82, faq82Demo } from "@/components/blocks/faq/faq82";

export default function Page() {
  return <Faq82 {...faq82Demo} />;
}

Props

PropTypeDefaultDescription
eyebrowstring"FAQ"Small label above the heading.
headingstring"Find your answer by topic"Section heading.
descriptionstringnoneSupporting copy under the heading.
itemsFaqItem[]noneFlat list of question/answer items, each tagged with a topic string; the topic rail and its counts are computed from this list.
classNamestringnoneExtra classes for the outer section element.

Types

type FaqItem = {
  topic: string;
  question: string;
  answer: string;
};

Behavior notes

  • The topic rail and its count badges are computed with useMemo from the items prop; there is no separate topics list to pass in, so a typo in an item's topic string creates a new rail entry.
  • The first topic in items' natural order is selected by default via a lazy useState initializer (not a mount-time effect), keeping the block hydration-safe.
  • Clicking a topic filters the accordion list to that topic's items and resets the open accordion index back to 0, so the previous topic's expanded state never leaks into the new one.
  • The accordion on the right allows only one item open at a time; clicking the currently open item collapses it.
  • This is a real 'use client' component; demo props live in the separate faq82.demo.tsx file so the live block preview (rendered from a Server Component) receives real data instead of undefined.