Message Scroller
A chat scroll container that anchors turns, follows streamed replies, holds your place as history loads, and jumps to any message.
Installation#
pnpm dlx shadcn@latest add @davinciui/message-scrollerUsage#
The provider owns scroll state and behavior; the scroller fills its parent, so place it in a height-constrained layout. It never owns messages, transport, or persistence — compose your own rows, markers, and inputs inside. Scroll position, anchoring, and follow-output are tracked imperatively and mirrored through data-* attributes, so scrolling never rerenders your rows.
MessageScrollerProvider
└── MessageScroller
├── MessageScrollerViewport
│ └── MessageScrollerContent
│ └── MessageScrollerItem
└── MessageScrollerButtonAnchoring Turns#
Keeping Context Visible#
Opening Saved Threads#
Loading Earlier Messages#
Jumping to Messages#
Tracking the Reader's Position#
Following the Live Edge#
Reading Scroll State#
Composition#
Use the following composition to build a Message Scroller:
MessageScrollerProvider
└── MessageScroller
└── MessageScrollerViewport
└── MessageScrollerContent
└── MessageScrollerItem
└── MessageAPI Reference#
| Prop | Type | Default |
|---|---|---|
autoScrollFollow new content only while the reader is at the live edge. | boolean | false |
defaultScrollPositionOpening position on first non-empty render, applied once. | "start" | "end" | "last-anchor" | "end" |
scrollEdgeThresholdDistance from either edge that counts as at the edge. | number | 8 |
scrollMarginMargin on the aligned edge for jumps and visibility. | number | 0 |
scrollPreviousItemPeekPrevious-item peek kept above a newly anchored row. | number | 64 |
messageIdStable row id for jumps, visibility, and prepend preservation. | string | — |
scrollAnchorTurn boundary that can anchor newly appended turns. | boolean | false |
preserveScrollOnPrependKeep the visible row stable when history prepends. | boolean | true |
directionTranscript edge the button scrolls toward. | "start" | "end" | "end" |
behaviorNative scroll behavior. Forced to auto under prefers-reduced-motion. | ScrollBehavior | "smooth" (button) / "auto" (commands) |
scrollToMessageJump to a mounted id; queues pre-mount targets. | (id, options?) => boolean | — |
useMessageScrollerFollowingLive-edge follow state for badges. Mirrored as data-following. | () => boolean | — |
data-scrollableEdges the viewport can scroll toward, on frame + viewport. | "start" | "end" | "start end" | — |
data-autoscrollingSet during programmatic scrolls to the latest message. | present while scrolling | — |
data-followingSet while streamed output is pinning to the live edge. | present while following | — |
Accessibility#
The viewport is a focusable region labelled Messages, and content is a log with aria-relevant additions for streamed rows. The jump button has a default aria-label, and becomes inert and untabbable when nothing can scroll. Labels are overridable.
Motion#
Programmatic scrolling uses native smooth behavior by default, tunable per command or button via behavior. prefers-reduced-motion forces auto scrolling, and the button's 200ms fade and translate are removed with motion-reduce.
View source
Keep in mind
Need a custom component?
I build bespoke UI components & websites tailored to your brand.

