Staaarter

Searchable Accordion

A controlled search input filters a list of FAQ items as you type, matching against both question and answer text. Filtered results render as a single-open-at-a-time accordion, with a friendly empty state when nothing matches.

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 dependencies and any missing npm packages, and installs them straight into your project.

npx shadcn add https://staaarter.com/r/searchable-accordion.json

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

Usage

The file also exports faq11Demo, 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 { Faq11, faq11Demo } from "@/components/blocks/faq/faq11";

export default function Page() {
  return <Faq11 {...faq11Demo} />;
}

Props

PropTypeDefaultDescription
headingstring"Frequently asked questions"Section heading.
descriptionstringundefinedOptional supporting copy under the heading.
searchPlaceholderstring"Search questions..."Placeholder text for the search input.
itemsFaq11Item[]noneFull list of question and answer entries to search over.
classNamestringnoneExtra classes for the outer section element.

Types

type Faq11Item = { question: string; answer: string };

Behavior notes

  • Real interactivity: a controlled search input filters items via useMemo on every keystroke, matching a case-insensitive substring against both the question and the answer text.
  • Filtered results render as a real accordion with a single item open at a time; typing a new search resets the open item to none.
  • When no item matches the current query, the accordion is replaced with an empty-state message that echoes the search term back to the user.
  • The search input has a real associated Label (visually present, not just aria-label) for accessibility.