Message Scroller
A chat scroll container that follows streaming content, anchors turns, keeps its place on prepend, and offers a jump-to-latest button.
Customize
Installation
npx shadcn@latest add @kinetic/message-scrollerUsage
Wrap the scroller in MessageScrollerProvider and give each MessageScrollerItem a messageId.
import {
MessageScroller,
MessageScrollerButton,
MessageScrollerContent,
MessageScrollerItem,
MessageScrollerProvider,
MessageScrollerViewport,
} from "@/components/kinetic/ui/message-scroller";
export function ChatLog({ messages }: { messages: { id: string; text: string }[] }) {
return (
<MessageScrollerProvider autoScroll>
<MessageScroller className="h-80 rounded-lg border">
<MessageScrollerViewport>
<MessageScrollerContent className="p-4">
{messages.map((message) => (
<MessageScrollerItem key={message.id} messageId={message.id}>
{message.text}
</MessageScrollerItem>
))}
</MessageScrollerContent>
</MessageScrollerViewport>
<MessageScrollerButton />
</MessageScroller>
</MessageScrollerProvider>
);
}Following new content
With autoScroll the view follows growing content until the user scrolls up. defaultScrollPosition sets where it starts: end, start or last-anchor.
<MessageScrollerProvider autoScroll defaultScrollPosition="last-anchor">...</MessageScrollerProvider>Anchors
Mark user turns with scrollAnchor so a new reply scrolls the question to the top, leaving scrollPreviousItemPeek pixels of the previous item visible.
<MessageScrollerItem messageId={id} scrollAnchor={role === "user"}>...</MessageScrollerItem>Jump button
MessageScrollerButton appears when the latest message is out of view. direction picks the edge, and unreadCount shows an animated counter.
<MessageScrollerButton unreadCount={3} />Hooks
useMessageScroller() returns scrollToEnd, scrollToStart and scrollToMessage. useMessageScrollerScrollable() reports whether each edge can scroll, and useMessageScrollerVisibility() returns the visible message ids.
const { scrollToMessage } = useMessageScroller();
scrollToMessage("m42");Motion preferences
Smooth scrolling falls back to instant jumps when reduced motion is enabled. blurPx and speed tune the jump button reveal.
API Reference
MessageScrollerProvider
Zero-dependency scroll state store coordinating sticky streaming autoScroll, initial scroll placement, anchor visibility, and prepend stabilization.
| Prop | Type | Default | Description |
|---|---|---|---|
autoScroll | boolean | false | Follows growing content automatically until the user scrolls upward. |
defaultScrollPosition | "start" | "end" | "last-anchor" | "end" | Initial scroll target on mount. |
scrollEdgeThreshold / scrollPreviousItemPeek / scrollMargin | number | 8 / 64 / 0 | Edge detection threshold, anchor peek height, and scroll-to-message offset in pixels. |
MessageScroller / MessageScrollerViewport / MessageScrollerContent / MessageScrollerItem
Scroll region landmark, ARIA log container with bottom safe padding, and item visibility tracker.
| Prop | Type | Default | Description |
|---|---|---|---|
preserveScrollOnPrepend (Viewport) | boolean | true | Maintains viewport offset when older messages are prepended above. |
messageId / scrollAnchor (Item) | string / boolean | scrollAnchor=false | Registers message ID for programmatic scrolling and marks turn anchoring. |
MessageScrollerButton
Kinetic Button-backed floating control entering via spatial Euler spring and blur, with directionalSwap unread counter and viewport focus recovery.
| Prop | Type | Default | Description |
|---|---|---|---|
direction / behavior | "start" | "end" / "smooth" | "auto" | "end" / "smooth" | Scrolls toward top or latest bottom edge with reduced-motion-safe behavior. |
variant / size | KineticButtonVariant / KineticButtonSize | "secondary" / "icon-sm" | Kinetic Button appearance and size (automatically expands width when unreadCount > 0). |
unreadCount / blurPx / speed | number / number / number | blurPx=4 / speed=1 | Optional animated unread counter badge, reveal blur radius (0-16px), and spring speed (0.25-4). |
useMessageScroller / useMessageScrollerScrollable / useMessageScrollerVisibility
Hooks providing scrollToEnd, scrollToBottom, scrollToStart, scrollToMessage, edge state, and visible anchor IDs.
| Prop | Type | Default | Description |
|---|---|---|---|
Hooks return | scrollToEnd / { start, end } / { currentAnchorId, visibleMessageIds } | - | Imperative navigation controls and reactive store snapshots. |