shadcn.io is not affiliated with official shadcn/ui
Related Questions FAQ Block for React
A cross-linked FAQ for a password manager: every answer ends in two related questions, and choosing one opens that row, scrolls to it and moves focus to its question.
Installation
Overview
A cross-linked FAQ for React with Base UI. Six questions sit in a narrow column of hairline rows under a short rule with + marks at its ends, each opened by a plus that turns into a cross. Every answer ends in two related questions as links; choosing one closes the row you were on, opens the one you chose, moves focus to its question and brings it to the top of the screen. The accordion is controlled, one answer at a time. It's built from Accordion and Guides, with CSS transitions for the entrance and your theme's tokens for every colour. For help centres where one answer usually raises the next question.
FAQ
How do the related links work?
Each question lists the ids of two others in related, and the block looks up their wording from the same QUESTIONS array, so a link can't name a question that doesn't exist. Choosing one opens that row, moves focus to its question button and, once the row you left has closed, scrolls it to the top of the screen. Without a script the links are plain anchors that jump to the row.
How is the accordion controlled?
A useState holds the open question and the Accordion reads it, so the links can change it.
The Accordion takes value as an array and onValueChange; the block keeps one id in it.
How do I add a question or change its links?
Edit QUESTIONS at the top of the file: each entry is an id, the question, its answer and the two ids in related. OPEN_QUESTION names the one that's open on load. Keep every id in related pointing at a question that exists.
How does it work with a keyboard and a screen reader?
Each question is a button inside its own h3. Choosing a related link moves focus to the question you chose, so a screen reader reads it and its new state, and Tab continues from there. The links sit in a list under a "Related questions" label, and the arrow beside each is decorative and flips in right-to-left languages.
Are the closed answers in the page's markup?
Yes. The Accordion takes hiddenUntilFound, so every closed answer stays in the markup as hidden="until-found": search engines see all of them, and the browser's find in page opens the answer that holds a match.
What moves, and what happens with reduced motion?
The header and the rows fade up once on load, the plus turns into a cross, and an answer eases open. With reduced motion the entrance is off and the plus becomes a cross without turning. Scrolling to the chosen row is a jump, never a smooth scroll. The answers also open and close at once, with no height animation.
Related
- Pro
Docs Links FAQ
Reading and sharingA FAQ for a mapping service where every answer ends in two guides from the docs, as links with a reading time and an arrow.
- Pro
Anchor Link FAQ
Reading and sharingA FAQ for a documentation host with a # link on every question that copies its address, and deep links that open and ring the matching answer on load.
- Pro
Table of Contents FAQ
NavigationA FAQ for an object-storage service with a sticky table of contents: three topics and their questions in an outline that follows the reader, beside topic bands that each hold an accordion.
- Pro
Breadcrumb FAQ
NavigationA drill-down help centre for a mobile carrier: four topic cells in a framed card, a breadcrumb bar, and each topic's questions behind a click.
- Pro
Share Popover FAQ
Reading and sharingA FAQ for an event ticketing platform whose open answer ends in a Share button: a popover with a copy-link button, an email and a QR code of the answer's link.
- Pro
Multi-Language FAQ
Reading and sharingAn FAQ in English, Spanish and Arabic for a relocation service: a language switcher swaps the title, questions and answers, and sets lang and dir so Arabic lays the block out from its end.