Skip to content
ProLifetime access for $199, paid once, every future release included
Truffle UI

Comments

ProNew

A comment thread with a composer, replies nested under their parent, emoji reactions, sorting and paging, in a plain or a chat-bubble style.

Installation

pnpm dlx shadcn@latest add @viewport/comments

First time? Add the @viewport registry to components.json. Setup takes one minute.

Usage

The code behind the preview above comes with Truffle Pro.

Props

PropTypeDefault
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.

—
userCommentAuthor

The 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"
titlestring

The noun in the heading, after the count.

"Comments"
totalnumber

Number shown in the heading. Defaults to the number of comments and replies.

—
sort"top" | "newest" | "oldest"

The order to start in.

—
reactionsstring[]

Emoji offered as reactions. The first one is the Like of the `bubble` variant.

REACTIONS
pageSizenumber

Comments shown before "Show more".

5
maxLengthnumber

Longest comment allowed, in characters.

1000
placeholderstring"Write a comment…"
signInBrand[]

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) => void

Called when the visitor adds or removes a reaction.

—
hasMoreboolean

Says the server has more comments than were passed in, so "Show more" calls `onLoadMore`.

—
onLoadMore() => void | Promise<void>—
loadingboolean

Shows placeholders while you fetch the comments.

—
disabledboolean

Closes the thread: comments stay readable, the composer and Reply are removed.

—
accentstring

Color of the Comment button and of active reactions. Defaults to the theme's primary color.

—
footerReact.ReactNode

Content under the thread, such as a link to your comment policy.

—
classNamestring—

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`.