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.
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.jsonPrefer 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
| Prop | Type | Default | Description |
|---|---|---|---|
| heading | string | "Frequently asked questions" | Section heading. |
| description | string | undefined | Optional supporting copy under the heading. |
| searchPlaceholder | string | "Search questions..." | Placeholder text for the search input. |
| items | Faq11Item[] | none | Full list of question and answer entries to search over. |
| className | string | none | Extra 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.
More FAQ Blocks
View all →collapsible-accordion
Collapsible Accordion
Stacked cards with expandable sections, for full-length answers in a compact format.
open-list-layout
Open List Layout
Questions with answers displayed directly below in a simple always-open list.
three-column-grid
Three Column Grid
Q&A pairs arranged in a responsive grid layout, always open.
tabbed-categories
Tabbed Categories
Sidebar navigation with category tabs and an accordion of that category's questions.
grouped-sections
Grouped Sections
FAQs organized into titled sections, each with its own independent accordion below it.
side-by-side-image
Side-by-Side Image
Accordion paired with a large image on the left or right.