Message Scroller
A conversation scroller that follows new messages, preserves reading position and counts unread messages, composed from UI SDK scroll area and core.
See it as an AI agent does.See this component the way an AI agent does.
Installation
npx shadcn@latest add @keyframery/message-scrollerThis adds components/keyframery/message-scroller.tsx and its primitive to your project, and installs UI SDK, along with scroll-area, which it builds on. The motion tokens are added to your global CSS the first time you install a component.
Usage
import {
MessageScroller,
MessageScrollerButton,
MessageScrollerContent,
MessageScrollerItem,
MessageScrollerLabel,
MessageScrollerViewport,
} from "@/components/keyframery/message-scroller"Motion
| Move | What you see |
|---|---|
| Direction | Messages added after the first frame rise 16px into place. |
| Unfold | Jump to latest rises from the bottom edge after the reader scrolls away. |
| Roll | The unread count rolls as new messages arrive. |
Timing and springiness follow the motion style you set. To change how fast this message scroller moves, pass speed:
<MessageScroller speed="fast">
…
</MessageScroller>"fast" is 0.6×, "slow" 1.4×, and a number sets the multiplier. With reduced motion turned on, nothing moves: changes happen at once or with a short fade.
Theming
Set these CSS variables on the component or a parent. Leave them unset to follow the light and dark theme. The open Customize panel below the preview lets you try these settings.
| Variable | What it changes | Default |
|---|---|---|
--message-scroller-face | Jump button surface | bg-background |
--message-scroller-ink | Jump button text | text-foreground |
--message-scroller-unread-face | Unread surface | bg-primary |
--message-scroller-font | Jump label size | text-[12.5px] |
--message-scroller-height | Jump button height | h-8 |
--message-scroller-icon-size | Jump icon | size-3.5 |
--message-scroller-gap | Message spacing | gap-4 |
--message-scroller-padding | Conversation inset | p-4 |
API reference
Every part takes className and children, along with the props of the element it renders. The parts are rendered by UI SDK, so they also take render, to draw your own element, and a function of their state for className and style.
MessageScroller
Renders a <div>, and takes its props too.
Prop
Type
MessageScrollerItem
Renders a <div>, and takes its props too.
Prop
Type
Other parts
These take the props of the element they render, and nothing else:
MessageScrollerButton: a<button>MessageScrollerContent: a<div>MessageScrollerLabel: a<span>MessageScrollerViewport: a<div>
Hooks
useMessageScrollerRoot
Call it inside the component to read and change its state.
Keyboard
| Key | What it does |
|---|---|
| Tab | Moves to the scroll viewport and jump-to-latest button. |
| Page Up / Page Down | Scrolls a focused conversation viewport. |
| Enter | Activates the focused jump-to-latest button. |
Accessibility
Roles, keyboard and focus are declared on the component's UI SDK primitive, and state is announced through the matching ARIA attributes. More in Accessibility.
Built on UI SDK's core
UI SDK doesn't ship a message scroller, so this one is defined with its core: one definePrimitive in components/keyframery/core/message-scroller-core.ts, with no React in it. UI SDK's adapters can render that same definition in Vue, Svelte, Solid and web components. To keep your own styling and take only the motion, import from @/components/keyframery/primitives/message-scroller.
Questions
How does the animated Message Scroller for UI SDK move?
Direction: Messages added after the first frame rise 16px into place. Unfold: Jump to latest rises from the bottom edge after the reader scrolls away. Roll: The unread count rolls as new messages arrive.
Do I need Motion or Framer Motion for the animated Message Scroller?
No. Every move is plain CSS, so there is nothing to install besides the component and UI SDK.
UI SDK has no message scroller. How is this one built on UI SDK?
Its behaviour is one definition written with UI SDK's core (definePrimitive), in components/keyframery/core/message-scroller-core.ts. Its parts are rendered by UI SDK's adapter, so they take render, state-based class names and data-slot, like every UI SDK component.
What happens to the Message Scroller when someone turns on reduced motion?
Nothing moves. State changes happen at once, or with a short fade.
More in Chat
All componentsMessage
Sender-aware chat messages with avatars, headers and read receipts that arrive in sequence, built on UI SDK core.
Trace
Steps rise in one after another, a running title has a light passing through it, a finished step's tick pops in and draws itself, and a row opens to its real height with its detail cascading in.