Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Voting Comments Block for React Aria

A question and four answers with an upvote toggle on each, a sort by votes or oldest, and an Accept button for the asker that moves the chosen answer first.

Framework
UI library

Preview

Preview width

Installation

Part of Pro
Pro unlocks the code and one-line install of every Pro button and text effect, plus the MCP for your AI editor.
Have Pro already? Sign in to open it.Opens here as soon as you're Pro.

Overview

Let readers sort the good answers from the rest, with this question and answers thread for React with React Aria. A compact header names the topic and holds an "Asking as kitlind" Switch. The frame opens with the question, then a band whose Segment Group orders the four answers by votes or oldest first. Each answer has an upvote Toggle with its count at the start (a 44 pixel target; press it again to take the vote back), the handle, the age and the words. Voting moves a number and never a row: the order is worked out from the typed votes, so nothing jumps under your finger. Turn on the switch and each answer shows an Accept Button: the accepted answer is checked, says "Accepted by the asker" in words and moves first, and accepting another moves the check. A polite status line names every change. It is built from Switch, Toggle, Segment Group, Button, Avatar, Badge and Guides, with a CSS entrance only. For developer Q and A, support forums and any thread where one answer should win.

FAQ

How do I fill it with my own question?

Edit QUESTION, ASKER and ANSWERS. An answer has an id, the author's handle, an ISO at, its body and the votes it has before yours. The ordering, the counts and the accepted state are worked out from that list. Handles are made up here; use your members' real display names and keep them in a bdi so a right-to-left name does not scramble the line.

Why doesn't the list reorder when I vote?

Order follows the typed votes, not your own, so pressing a toggle changes one number and nothing else. That keeps the page still, and means two people looking at the same answers see the same order. If you want live reordering, sort by the total including yours in orderedOf, and hold the heights of the rows so nothing jumps while a finger is on it.

How does Accept work?

The Asking as switch stands for "I am the person who asked". With it on, each answer shows Accept; the accepted one is pressed, moves to the top and states "Accepted by the asker". Pressing Accept on the same answer again takes it back, and accepting another moves it. Focus stays on the button you pressed, even though its row moves. In a real app, show the control only to the asker and check that on the server.

What stays local?

The votes, the accepted answer and the sort. The status line says what changed, and nothing is saved or sent. To make it real, send the vote from the toggle's handler, store at most one vote per person and answer, and return the new totals; the toggle shows the pressed state from the server's answer.

Is it accessible?

Each vote toggle is named after its answer ("Upvote the answer by quietheron") and reports whether it is pressed; the count is part of its name so it is read as "41 votes". Accepted is written in words with a check, not shown by colour. The answers are an ordered list, the sort is a labelled group and the status line is read out politely.

How does it look on a phone?

The switch drops under the sentence and the sort control fills the width of its band. Each answer keeps its vote toggle at the start with a target of at least 44 pixels, and the Accept button sits under the words.