Comments
ProNewA comment thread with a composer, replies nested under their parent, emoji reactions, sorting and paging, in a plain or a chat-bubble style.
Installation
First time? Add the @viewport registry to components.json. Setup takes one minute.
Usage
Props
| Prop | Type | Default |
|---|---|---|
| comments* | Comment[]The comments to start with. The widget keeps its own copy and adds new comments and reactions to it; pass an array with different comments to replace it. | — |
| user | CommentAuthorThe signed-in visitor. Without one, the composer asks for a name. | — |
| variant | "card" | "bubble"`card` draws reaction pills under plain text; `bubble` wraps each comment in a chat bubble with Like and Reply links. | "card" |
| title | stringThe noun in the heading, after the count. | "Comments" |
| total | numberNumber shown in the heading. Defaults to the number of comments and replies. | — |
| sort | "top" | "newest" | "oldest"The order to start in. | — |
| reactions | string[]Emoji offered as reactions. The first one is the Like of the `bubble` variant. | REACTIONS |
| pageSize | numberComments shown before "Show more". | 5 |
| maxLength | numberLongest comment allowed, in characters. | 1000 |
| placeholder | string | "Write a comment…" |
| signIn | Brand[]Adds "Sign in with" buttons for these providers above the guest composer. | — |
| onSignIn | (provider: Brand) => void | — |
| onSubmit | (draft: CommentDraft) => void | Comment | Promise<void | Comment>Called with a new comment or reply. Return a promise to show progress; reject it to show the error and keep the text. Resolve with a `Comment` to use your own id. | — |
| onReact | (commentId: string, emoji: string, active: boolean) => voidCalled when the visitor adds or removes a reaction. | — |
| hasMore | booleanSays the server has more comments than were passed in, so "Show more" calls `onLoadMore`. | — |
| onLoadMore | () => void | Promise<void> | — |
| loading | booleanShows placeholders while you fetch the comments. | — |
| disabled | booleanCloses the thread: comments stay readable, the composer and Reply are removed. | — |
| accent | stringColor of the Comment button and of active reactions. Defaults to the theme's primary color. | — |
| footer | React.ReactNodeContent under the thread, such as a link to your comment policy. | — |
| className | string | — |
Accessibility
- Each comment is an `article` named after its author; replies are nested lists, and "View 3 replies" is a button with `aria-expanded`.
- Reactions are toggle buttons with `aria-pressed` and a name such as "👍 12"; the reaction and emoji pickers are popovers that take focus and return it.
- The composer is a labelled form: Enter adds a line, Ctrl or Cmd with Enter posts, and Escape closes an empty reply box and returns focus to its Reply button.
- Posting announces "Comment posted" through a polite live region; a failure is announced as an alert and the text is kept.
- Timestamps are `time` elements with the full date as a tooltip, and update on their own without being announced.
- Entrance, reaction pop and reply reveal are dropped under `prefers-reduced-motion`.