shadcn.io is not affiliated with official shadcn/ui
Sortable FAQ Block for React
A FAQ for a garden-planner app whose questions really sort: a three-way control in a narrow start column reorders eight rows by most asked, newest or A to Z.
Installation
Overview
A sortable FAQ for React with Base UI. A narrow start column holds the title, a sentence and a pill-shaped control with three choices, Most asked, Newest and A to Z; the eight questions sit in the end column behind a split divider that runs from the page's top rule to the block's end. Choosing a sort moves the rows and says so in words under the control. Each row carries its key: how often it's asked, such as "2.1k asks", and a "New" badge on the latest additions. Nothing changes height. On a phone the header stacks above the rows and the control goes full width. It's built from Accordion, Segment Group, Badge and Guides, with CSS transitions for the entrance and your theme's tokens for every colour. For help centres where popularity, freshness or alphabet each help a different reader.
FAQ
How do I change the questions and their keys?
Edit QUESTIONS at the top of the file: each entry has an id, the question and its answer, asks (how often it was asked, a number) and order (its place in the order the questions were written, higher is newer). NEW_FROM is the order from which a question carries the "New" badge. SORTS holds the three choices; add one by adding a case to sorted.
How does the sorting work?
sorted returns a copy of the questions in the order the choice asks for: by asks high to low, by order high to low, or by the question's text with the browser's alphabetical order. The rows are the same elements in a new order, so a row you opened stays open after the sort.
What do screen readers hear?
The control is a group named "Sort the questions" with three options, and the line under it, "Sorted by A to Z", is a polite status that is read out when you choose. Each question is a button inside its own h3 under the section's h2, and the count of asks is part of the button's name.
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".
Related
- Pro
Topic Select FAQ
Topics and filtersA short FAQ for a bike-share with a topic Select at the end of its header: choose a topic and its questions fill the rows below, or choose All topics for all twelve.
- Pro
Live Search FAQ
SearchA searchable FAQ for a notes app: a start-aligned header, a band with a full-width search field and a live count, and ten questions that filter as you type, open every match and mark the matched words.
- Pro
Categorized FAQ
Topics and filtersA topic-tabbed FAQ for a bookkeeping app: a compact header, a band of line tabs with a count on each, and one accordion per topic.
- Pro
Accordion FAQ
Accordion listsA side-header FAQ for a web analytics tool: the title, one sentence and a contact prompt beside seven questions in an accordion, behind a split divider.
- Pro
Popularity Bars FAQ
Votes and reactionsA FAQ for a tea shop ordered by how often each answer is read: a count column at the end of every row and a thin bar under each question, as long as its count.
- Pro
Multi Select FAQ
Topics and filtersA topic-chip FAQ for an outdoor-gear rental: any number of chips can be on, and the list shows the union of their questions, with a live count.