shadcn.io is not affiliated with official shadcn/ui
Votes FAQ Block for React
A community FAQ for a product forum: six accordion rows with a vote rail at the start of each, an up arrow, a score and a down arrow, one vote per answer that can be taken back.
Installation
Overview
A votes FAQ for React with Base UI. A start-aligned header with a "Community answers" badge sits over six questions that run from rail to rail under a rule with + marks. At the start of every row a vote rail, set off by a second hairline with its own + marks, holds an up arrow, a score and a down arrow; under each question a quiet line says which topic it belongs to and how many replies it has. You get one vote per answer: press an arrow and it turns to the text colour on the page colour (never the primary) and the score moves by one, press it again to take it back, or press the other arrow to swap. The page's rails and top rule come from the Guides spine, so the block lines up with its neighbours in a stack. It's built from Accordion, Toggle, Badge and Guides, with CSS transitions for the entrance and your theme's tokens for every colour. For forums, Q and A sections and any list where members rank the answers.
FAQ
How do I change the questions and the scores?
Edit QUESTIONS at the top of the file: each entry is an id, the question, its answer, a meta line ("Imports, 38 replies") and base, the score before your vote. OPEN_QUESTION names the row that's open on load. One answer is open at a time.
Add multiple to the Accordion to let several stay open.
Are the votes saved?
No. Your votes live in the component's state, keyed by question, so a reload clears them and nobody else sees them. To store them, call your own endpoint from the cast function: it already knows the question and whether the vote went up, down or was taken back.
How is the score worked out?
It's base plus your vote: one more with an up arrow, one fewer with a down arrow, so swapping from up to down moves the score by two. The score is wrapped in bdi so a right-to-left layout keeps the digits in order.
How does it work with a keyboard and a screen reader?
Each question is a button inside its own h3 under the section's h2. The rail is a group named "Vote on:" and the question, and its two arrows are toggle buttons named Upvote and Downvote that say whether they're pressed. In the Tab order they follow their own question. A polite status line reads "Upvoted. Score 143." after each press.
Tab moves between the questions and the arrows; the arrow keys don't move between questions on this base.
Related
- Pro
Feedback FAQ
Votes and reactionsA centred FAQ for a scheduling app: seven accordion rows whose open answers end in a Was this helpful? foot with Yes and No, reason chips after a No, and a polite thank-you.
- Pro
Rating FAQ
Votes and reactionsA reverse-split FAQ for a recipe app: seven rows that each show an average rating, with a one-to-five scale at the foot of every open answer and the header beside the rows.
- Pro
Reactions FAQ
Votes and reactionsA start-aligned FAQ for a design-feedback tool: six rows whose open answers end in four reaction chips, each a face or a heart with a word and a count, plus running totals.
- 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
Reaction Pills Testimonials
Chats and postsA launch-week chat in a split: the headline and a Shine Button in a rail, and four messages ruled apart by hairlines, each with celebrate, love and ship-it reaction pills that really toggle and count.
- 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.