Skip to main content

Conversation

A chat transcript that follows the newest message while an answer streams, with a button back to the end. Scroll up while the answer streams: the view stays put, the bottom edge fades, and a button takes you back.

Desktop viewport
Tablet viewport
Mobile viewport

When to use

  • Show the messages of a chat with an assistant or a model, and keep the newest text in view while an answer streams.
  • Use Message for each message in it.
  • Prefer List for items that do not grow at the end while the reader watches.

Composition

Conversation.Root├── Conversation.Viewport│   └── Conversation.Content│       └── Message.Root└── Conversation.ScrollButton

Polymorphism

Conversation.Viewport and Conversation.Content take asChild. Conversation.Root and Conversation.ScrollButton do not: the root renders the status region beside its children, and the button owns its icon and position.

How it follows the end

Conversation.Viewport follows the end while the reader is at the end, so streamed text never lands below the fold. It works as Amp does:

  • When the reader scrolls up by any means (wheel, touch, keys, or the scrollbar), the view stays where they put it. The bottom edge fades, and Conversation.ScrollButton shows.
  • The view follows the end again when the reader scrolls back to it, presses Conversation.ScrollButton, or sends a message. A message from the person is a Message.Root with from="user".
  • On mount, the view starts at the end. If something already moved it, such as useScrollAnchor restoring the reader's place, the view stays there.

The top and bottom edges fade when there is more to read past them, with scroll-fade-y.

Accessibility

Conversation.Root owns the chat's one status announcement. Set streaming while an answer streams. Screen readers then hear "Answering…" when it starts and "Answer ended." when it ends. Nothing reads the answer aloud word by word, because that interrupts a reader who is busy with other content.

Conversation.Viewport is a named region that takes focus, so a keyboard can scroll a transcript that has no links or buttons. When Conversation.ScrollButton hides after a press, focus moves to the viewport.

API Reference

Conversation.Root

The transcript: it holds the viewport and the scroll button, and owns the status announcement. Give it a height, such as flex-1 in a flex column.

All props from div, plus:

PropTypeDefaultDescription
streaming?booleanfalseTrue while an answer streams. Screen readers hear "Answering…" when it starts and "Answer ended." when it ends.
Data AttributeValueDescription
data-scrolled-uppresent while the end is out of viewPresence-only. Shows Conversation.ScrollButton.
data-streamingpresent while streamingPresence-only. Style with data-streaming:.

The children sit in a display: contents wrapper, data-slot="conversation-label", so a translated loading message can change to a transcript.

Conversation.Viewport

The region that scrolls and follows the end. Name it with aria-label.

All props from div, plus:

PropTypeDefaultDescription
asChild?booleanfalseRender as a different element by passing a child.

Conversation.Content

The ordered list of messages. Set the measure and padding here, such as mx-auto max-w-3xl p-4.

All props from ol, plus:

PropTypeDefaultDescription
asChild?booleanfalseRender as a different element by passing a child.

Conversation.ScrollButton

The round button over the bottom edge of the viewport that goes back to the newest message. It shows only while the end is out of view.

All props from Icon Button except appearance, asChild, icon, intent, label, and type, plus:

PropTypeDefaultDescription
label?string"Scroll to the latest message"The accessible name of the button.