shadcn.io is not affiliated with official shadcn/ui
Basic Comments Block for Radix UI
A ticket discussion with comments and replies in two levels, Oldest or Newest sorting, and a composer where you can edit or delete your own comments and undo a delete.
Installation
Overview
Give a ticket, a spec or a pull request a place to talk, with this comment thread for React with Radix UI. A compact header names the ticket and holds a Segment Group that sorts the comments Oldest or Newest first. Under it a hairline frame holds the thread: three comments and three replies in two levels, each reply under a thin rail, in a labelled scroll region that keeps its height so posting never moves the page. Every comment with replies folds them behind a Collapsible button that says how many ("Hide 2 replies"). The comments marked You carry Edit, which turns the words into a Textarea with Save and Cancel and adds an "edited" mark, and Delete, which collapses the row to "Comment deleted. Undo" until your next action. Reply points the one composer under the thread at that comment, and Ctrl or ⌘ + Enter posts. The composer is a Field with a Shine Button, a problem line that is always in place and a polite status line that says what changed. It is built from Segment Group, Collapsible, Textarea, Field, Avatar, Badge, Kbd, Shine Button and Guides, with a CSS entrance only. For issue trackers, review tools and any page where a team discusses one thing.
FAQ
How do I fill it with my own ticket?
Edit PEOPLE and START. Each comment has an id, who wrote it (by, a person's id), an ISO at, its body, whether it was edited and the parent it answers (empty for a comment on the ticket). ME names the person using the page: their comments say "You" and are the only ones with Edit and Delete. Ages such as "3 h ago" are worked out from AS_OF and the typed times, never from the clock, so the server and the browser print the same words. The block draws two levels; deeper conversations belong in Nested Threads.
What stays local, and how do I make it real?
Everything. Posting, editing, deleting and undoing change a list in the page, and the status line says "Posted in this demo. Nothing was sent." To make it real, call your API from post, save and remove, then replace the item in the list with what the server returns (its id and time). A real app should also check on the server that the person owns the comment before it edits or deletes it: hiding the buttons is not a permission check.
How does Delete and Undo work?
Delete collapses the row to "Comment deleted. Undo" and moves focus to Undo. The deletion becomes final on your next action: posting, replying, editing or deleting another comment. Until then Undo puts the comment back and returns focus to its Delete button. The count in the heading leaves out a comment that is waiting for Undo. Nothing expires on a timer, so a keyboard or screen reader user never loses the chance to undo.
Is it accessible?
The thread is a labelled region you can reach with Tab and scroll with the arrow keys. Comments are an ordered list with a nested list of replies per comment; every action says whose comment it is for ("Reply to Linnea Aberg") while showing a short visible word. Time is a real time element. The composer has a label, a problem line tied to the field and a Ctrl or ⌘ + Enter shortcut that is described to screen readers; the status region is present from load and is read out politely when something changes. Character counts are spoken only at 20, 10 and 0 left.
How does the composer behave?
An empty comment says "Write something first." and one under three characters says how many more it needs, in a line that is always in place so the Comment button never moves. A comment can be 600 characters; the count shows in the last 100. A posted comment lands at the end of the thread (at the start in Newest order), marked You and "just now", and the region scrolls to it. Choosing Reply changes the label above the box to "Replying to ..." and the button to Post reply; Cancel reply goes back to a comment on the ticket.
How does it look on a phone?
The sort control drops under the sentence and fills the width. Avatars shrink to a small size and the reply rail thins to two pixels. Actions stay on one wrapping row under the text, and the composer's button goes full width under the shortcut hint. The thread region keeps its height and scrolls on its own.