Installation
Usage
"use client"
import { CommentThread } from "@/components/comment-thread"
export function Discussion() {
return (
<CommentThread
me={{ name: "Sofia Rossi" }}
people={[{ name: "Emily Carter", detail: "Product" }]}
anchor="On Q3 launch plan"
defaultComments={[
{ id: "1", author: "Emily Carter", body: "Can we move the launch to the 14th?", at: "2026-11-05T09:30:00Z" },
]}
onSend={async (body, replyTo) => {
await fetch("/api/comments", { method: "POST", body: JSON.stringify({ body, replyTo }) })
}}
/>
)
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
| comments / defaultComments | ThreadComment[] | [] | The thread, kept by you or by the component. Each has id, author, body, at, and optionally avatar, reactions, replies, pending. |
| onCommentsChange | (comments) => void | — | Called with the new thread after any change. |
| me | { name, avatar? } | — | You: new comments are written as this person. |
| people | { name, detail?, avatar? }[] | [] | Who can be mentioned with @. |
| onSend | (body, replyTo) => void | Promise<void> | — | A new comment shows at once as Sending…; resolve to confirm it, or throw to take it back and restore the text. |
| onReact | (id, emoji, on) => void | — | Called when you add or remove a reaction. |
| resolved / defaultResolved | boolean | false | Whether the thread is resolved. |
| onResolvedChange | (resolved) => void | — | Called when it is resolved or reopened. |
| anchor | ReactNode | — | What the thread is about, shown in its header. |
| typing | string[] | [] | Names of people typing right now. |
| emojis | string[] | six common reactions | The reactions offered in the picker. |
| label | string | "Comments" | Accessible name of the thread. |
| placeholder | string | "Reply… type @ to mention someone" | Text in the empty box. |
Accessibility
- The composer sends on Enter and Shift+Enter makes a new line.
- Typing @ opens a list of people: arrow keys choose, Enter or Tab picks, Escape closes.
- Reactions are toggle buttons that say their count; the picker works with the arrow keys and Escape.
- Sending, replies, reactions and resolving are announced to screen readers.
- Motion stops under prefers-reduced-motion.
Changelog
- v1.0.0Latest
First release.