Message Scroller
A user-respecting transcript scroller for live replies, saved conversations, and long message history.
Message Scroller manages the scrolling behavior around a conversation without owning the message UI. It follows new content only while the reader is at the live edge, preserves their position when older history is prepended, and exposes commands for navigation.
New Chat
How can I help you today?
Morning, Zenos!
What are we working on today? Press send to start a new conversation.
The preview uses useChat from @ai-sdk/react with a local scripted ChatTransport. It exercises
the same message, status, and streamed-part shapes as an AI-backed application without sending a
network request or requiring an API key. Replace the mock transport with your application transport
when connecting a real model.
Import
Section titled “Import”import { Message, MessageScroller } from "@zentara-co/zenos-ui";import { useChat } from "@ai-sdk/react";Composition
Section titled “Composition”Give the root a height-constrained parent, then compose the viewport, live-region content, and stable message items. MessageScroller.Button appears after the reader moves away from the latest message.
<div className="h-96"> <MessageScroller.Provider> <MessageScroller> <MessageScroller.Viewport> <MessageScroller.Content> {messages.map((message) => ( <MessageScroller.Item key={message.id} messageId={message.id} scrollAnchor={message.startsTurn} > <Message>{message.content}</Message> </MessageScroller.Item> ))} </MessageScroller.Content> </MessageScroller.Viewport> <MessageScroller.Button /> </MessageScroller> </MessageScroller.Provider></div>Following live replies
Section titled “Following live replies”autoScroll defaults to true. Appended content follows the live edge only while the reader is already there. Scrolling upward releases that behavior, so a streamed response cannot pull the reader away from older content. Set autoScroll={false} when the application should never follow appended content automatically.
<MessageScroller.Provider autoScroll={false}>{/* transcript */}</MessageScroller.Provider>Opening saved conversations
Section titled “Opening saved conversations”Choose the initial position with defaultScrollPosition:
"end"opens at the newest message."start"opens at the beginning."last-anchor"opens at the latest item marked withscrollAnchor.
Use scrollPreviousItemPeek to control the space shown above an anchored turn.
<MessageScroller.Provider defaultScrollPosition="last-anchor" scrollPreviousItemPeek={64}> {/* transcript */}</MessageScroller.Provider>Loading older history
Section titled “Loading older history”preserveScrollOnPrepend defaults to true. When older items are inserted before the current list, the viewport compensates for the added height so the visible message stays in place. Keep every messageId stable across pagination.
Scroll commands
Section titled “Scroll commands”Use useMessageScroller inside the provider for transcript navigation. scrollToMessage returns false when the requested ID is not mounted.
function TranscriptControls() { const { scrollToEnd, scrollToMessage, scrollToStart } = useMessageScroller(); return ( <> <button onClick={() => scrollToStart({ behavior: "smooth" })}>First</button> <button onClick={() => scrollToMessage("message-42", { block: "center" })}> Jump to result </button> <button onClick={() => scrollToEnd({ behavior: "smooth" })}>Latest</button> </> );}Visibility
Section titled “Visibility”useMessageScrollerVisibility returns visibleMessageIds and the nearest visible currentAnchorId. Use that state for a transcript outline, unread markers, or a synchronized search result list.
The jump button uses logical positioning and mirrors automatically in a dir="rtl" region or DirectionProvider. Message alignment remains the responsibility of the composed Message and Bubble parts.
MessageScroller.Provider MessageScroller.Root MessageScroller.Viewport MessageScroller.Content MessageScroller.Item MessageScroller.Button
API
| Prop | Type | Default | Description |
|---|---|---|---|
autoScroll | boolean | true | Follows appended content while the reader remains at the live edge. |
defaultScrollPosition | start | end | last-anchor | end | Initial position when the transcript is mounted. |
preserveScrollOnPrepend | boolean | true | Preserves the visible position when older history is prepended. |
scrollPreviousItemPeek | number | 48 | Space above an item when a turn anchor is positioned. |
messageId | string | — | Stable Item identifier used by commands and visibility tracking. |
scrollAnchor | boolean | false | Marks an Item as a conversation-turn boundary. |
target | start | end | end | Transcript boundary targeted by MessageScroller.Button. |
native props | React.HTMLAttributes<HTMLDivElement> | — | Forwards native attributes, events, aria-*, data-*, className, style, and ref. |
Unless narrowed above, each DOM-rendering part also accepts its underlying native or Base UI props,
including className, style, aria-*, and data-*.
Accessibility
Section titled “Accessibility”The viewport is keyboard-focusable and labeled “Conversation” by default. Content uses role="log" with a polite live region for additions. Keep sender names and message status in readable text, provide stable IDs, and avoid announcing large batches when loading historical messages.
The behavior is informed by the shadcn Message Scroller while using Zenos tokens, compound APIs, and direction conventions.