Message Scroller
MessageScroller keeps a conversation at its newest message while a reply arrives, and leaves your place alone when you scroll up.
<MessageScroller> <ScrollArea fade aria-label="Transcript"> <MessageScrollerContent> <MessageScrollerItem messageId="m1" scrollAnchor> … </MessageScrollerItem> </MessageScrollerContent> <MessageScrollerButton aria-label="Jump to the latest"> … </MessageScrollerButton> </ScrollArea></MessageScroller>Use a MessageScroller for a transcript that grows while people read it, such as a chat, a support thread or a live log. While people are at the end, it follows new content as it arrives. When they scroll up, it keeps their place until they scroll back to the end. For a list that does not grow, use a ScrollArea on its own.
A MessageScroller does not add a scroll box. It uses the ScrollArea or ShellScroll inside it as its viewport, so the pane keeps its fade, its scrollbars and its floating header. You draw the rows, the words and the counts yourself, and the Conversation block shows one way to lay out a turn.
Put each row in a MessageScrollerItem inside MessageScrollerContent. When a new row has scrollAnchor, it moves near the top of the view, so people start a long reply from its beginning. Older history can load above the view without moving what people are looking at.
defaultScrollPosition sets where the transcript opens: at the end, which is the default, at the start, or at the last row marked with scrollAnchor. Set autoScroll={false} to stop following new content.
MessageScrollerButton returns people to the latest message. It appears only while there is more content below, and it uses the theme's material because the transcript passes behind it. Give it an aria-label in your own words.
MessageScrollerContent is a live region, so screen readers announce new rows. Name the transcript with aria-label on the ScrollArea. To build your own controls, call useMessageScroller, useMessageScrollerScrollable or useMessageScrollerVisibility inside the MessageScroller. They move the transcript, tell you whether there is more to scroll at each end, and tell you which rows are on screen.
The behaviour comes from shadcn/ui's Message Scroller (MIT), through the @shadcn/react package. Kookie adds the styling and lets your own ScrollArea act as the scroller.
Topics
Every symbol this component exports, grouped by the job it does. Each one carries the props it declares; each one has an anchor of its own.
Following new content
MessageScroller
MessageScroller keeps a conversation at its newest message while a reply arrives, and leaves your place alone when you scroll up.
| Prop | Type | What it does |
|---|---|---|
autoScroll? | boolean | Keeps the newest content in view while the user is at the end. |
children? | React.ReactNode | A ScrollArea or a ShellScroll that holds the transcript and the jump button. |
defaultScrollPosition? | "start" | "end" | "last-anchor" | Where the transcript opens: at the end, at the start, or at the last anchored message. |
Rows, anchors and the jump button
MessageScrollerItem
One row of the transcript. Give it a messageId to scroll to it, and set scrollAnchor on the row that starts a new turn
| Prop | Type | What it does |
|---|---|---|
messageId? | string | A stable id for the message. |
scrollAnchor? | boolean | Scrolls this message near the top when it arrives, so the user sees the reply from its start. |
It also takes every prop of a <div>.
MessageScrollerButton
A button that returns to the latest message. It appears only while there is more content below and sits at the bottom of the view
| Prop | Type | What it does |
|---|---|---|
aria-label | string | The accessible name of the button, such as "Jump to latest". |
backdrop? | boolean | Whether content passes behind the button. |
children | React.ReactNode | The icon of the button. |
className? | string | Your classes, appended to the ones this component resolves rather than replacing them. |
size— The only thing a MessageScroller draws is its jump button. The rows are your own components, so set their sizes on them.- A viewport of its own — Two scroll boxes in one pane fight over the scroll position, so the MessageScroller uses the
ScrollAreathat is already in the pane. - A default label for the jump button — Any built-in label would be in English, so the button requires an
aria-labelthat you write in your app's language.