Message Scroller
A Shadcn-styled chat scroll container with bottom end-follow, history-safe pausing, and a floating jump-to-latest control.
Message Scroller is built for chat feeds and streamed replies. It automatically follows newly appended items while the reader is at the bottom, holds position when the reader scrolls up into history, and provides a floating jump button to return on demand. The examples on this page use the Shadcn Rhea style preset.
Preview
Section titled “Preview”<div
class="h-80 w-full max-w-md overflow-hidden rounded-xl border border-border"
>
<proto-ui-shadcn-message-scroller-root
id="chat-scroller"
style-profile="rhea"
>
<proto-ui-shadcn-message-scroller-viewport style-profile="rhea">
<div class="flex flex-col gap-3 p-4 pb-14">
<div>
Every time our AI streams a reply, the whole thread jumps
around.
</div>
<div>
Message Scroller only auto-scrolls while the reader is
already at the bottom.
</div>
</div>
</proto-ui-shadcn-message-scroller-viewport>
<proto-ui-shadcn-message-scroller-jump style-profile="rhea">
<span aria-hidden="true">↓</span>
<span class="sr-only">Jump to latest</span>
</proto-ui-shadcn-message-scroller-jump>
</proto-ui-shadcn-message-scroller-root>
</div>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
const root = document.querySelector('#chat-scroller');
setElementProps(root, {
styleProfile: 'rhea',
a11yLabel: 'Assistant conversation',
});
</script>Installation
Section titled “Installation”Available starting in 0.3.0-rc.1 and later releases. Import the prototypes directly from @proto.ui/prototypes-shadcn/message-scroller and adapt them for your target runtime.
import { messageScrollerRoot, messageScrollerViewport, messageScrollerJump,} from '@proto.ui/prototypes-shadcn/message-scroller';Message Scroller fills its parent, so wrap it in a height-constrained container:
<div className="flex h-80 flex-col overflow-hidden rounded-xl border border-border"> <ShadcnMessageScrollerRoot styleProfile="rhea" a11yLabel="Assistant conversation"> <ShadcnMessageScrollerViewport styleProfile="rhea"> <div className="flex flex-col gap-3 p-4 pb-14"> {messages.map((message) => ( <div key={message.id}>{message.text}</div> ))} </div> </ShadcnMessageScrollerViewport> <ShadcnMessageScrollerJump styleProfile="rhea"> <span aria-hidden="true">↓</span> <span className="sr-only">Jump to latest</span> </ShadcnMessageScrollerJump> </ShadcnMessageScrollerRoot></div>Anatomy & Behavior
Section titled “Anatomy & Behavior”Message Scroller consists of Root, Viewport, and Jump:
- Follow only while at the bottom: Newly appended messages scroll into view automatically when the reader is already at the end. Scrolling up pauses auto-follow immediately and preserves reading position.
- Focus-preserving Jump button: Activating
Jumpscrolls back to the latest entry and re-engages end-follow without stealing keyboard focus from composers or other controls. Use the defaultsize="icon"for compact icon buttons orsize="pill"for text labels and unread counts. - Application-owned unread count: Pass
newContentCountfrom your own application state rather than letting the container guess unread semantics. - Accessible naming: Set
a11yLabelonRootto label the scrollable region (defaults to'Messages'). - Style presets (
styleProfile): All three parts supportvega,nova,maia,lyra,mira,luma,sera,rhea, andnew-york-v4, inheriting the nearest Style Scope when omitted or set toinherit.
Stable-key position and selection restoration
Section titled “Stable-key position and selection restoration”To restore reading position by stable key or preserve text selection across updates, compose the public Base asMessageScrollerReading hook after the Shadcn Viewport. The hook coordinates anchor capture, exact-key or predecessor restoration, and selection restoration on the same scroll surface, while your application keeps control of content IDs, DOM/Range work, and storage. See Base Message Scroller for details.
Examples
Section titled “Examples”Live Feed & Unread Counter
Section titled “Live Feed & Unread Counter”Click Append reply while at the bottom to watch automatic end-following. Scroll up first and append again to see position hold steady while newContentCount and the pill Jump label update.
<div
class="h-64 w-full max-w-md overflow-hidden rounded-xl border border-border"
>
<proto-ui-shadcn-message-scroller-root
id="live-scroller"
style-profile="rhea"
>
<proto-ui-shadcn-message-scroller-viewport
id="live-viewport"
style-profile="rhea"
>
<div
id="live-messages"
class="flex flex-col gap-3 p-4 pb-14"
></div>
</proto-ui-shadcn-message-scroller-viewport>
<proto-ui-shadcn-message-scroller-jump
id="live-jump"
style-profile="rhea"
>
Jump to latest ↓
</proto-ui-shadcn-message-scroller-jump>
</proto-ui-shadcn-message-scroller-root>
</div>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
const root = document.querySelector('#live-scroller');
const jump = document.querySelector('#live-jump');
setElementProps(root, {
styleProfile: 'rhea',
newContentCount: 0,
a11yLabel: 'Live release feed',
});
setElementProps(jump, { styleProfile: 'rhea', size: 'pill' });
</script>Group Channel & Event Markers
Section titled “Group Channel & Event Markers”Mix multi-author messages, avatars, and inline system event markers inside one transcript with a size="pill" unread jump control.
<div
class="h-72 w-full max-w-md overflow-hidden rounded-xl border border-border"
>
<proto-ui-shadcn-message-scroller-root
id="group-scroller"
style-profile="rhea"
>
<proto-ui-shadcn-message-scroller-viewport style-profile="rhea">
<div class="flex flex-col gap-3 p-4 pb-14">
<div>Maya: Staging build is green.</div>
<div>— Marcus joined the channel —</div>
<div>
Marcus: Position holds steady while new rows append.
</div>
</div>
</proto-ui-shadcn-message-scroller-viewport>
<proto-ui-shadcn-message-scroller-jump
id="group-jump"
style-profile="rhea"
>
2 new messages ↓
</proto-ui-shadcn-message-scroller-jump>
</proto-ui-shadcn-message-scroller-root>
</div>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
setElementProps(document.querySelector('#group-scroller'), {
styleProfile: 'rhea',
a11yLabel: 'Release channel messages',
newContentCount: 2,
});
setElementProps(document.querySelector('#group-jump'), {
styleProfile: 'rhea',
size: 'pill',
});
</script>Jump Control State
Section titled “Jump Control State”Jump inherits Button interaction semantics. Disabling Jump suppresses jump activation while keeping manual scrolling unaffected.
<div
class="h-56 w-full max-w-md overflow-hidden rounded-xl border border-border"
>
<proto-ui-shadcn-message-scroller-root
id="disabled-scroller"
style-profile="rhea"
>
<proto-ui-shadcn-message-scroller-viewport style-profile="rhea">
<div class="flex flex-col gap-2.5 p-4 pb-14">
<div>09:00 · Connected to support session #4821</div>
<div>09:10 · Session marked resolved.</div>
</div>
</proto-ui-shadcn-message-scroller-viewport>
<proto-ui-shadcn-message-scroller-jump
id="disabled-jump"
style-profile="rhea"
>
Jump to latest ↓
</proto-ui-shadcn-message-scroller-jump>
</proto-ui-shadcn-message-scroller-root>
</div>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
setElementProps(document.querySelector('#disabled-scroller'), {
styleProfile: 'rhea',
a11yLabel: 'Support transcript',
newContentCount: 3,
});
setElementProps(document.querySelector('#disabled-jump'), {
styleProfile: 'rhea',
size: 'pill',
disabled: true,
});
</script>| Prop | Type | Default |
|---|---|---|
newContentCount | number | 0 |
a11yLabel | string | 'Messages' |
styleProfile | ShadcnStyleChoice | inherit → nearest scope → new-york-v4 |
Viewport
Section titled “Viewport”| Prop / Expose | Type | Notes |
|---|---|---|
styleProfile | ShadcnStyleChoice | inherit → nearest scope → new-york-v4 |
atEnd (expose) | ExposeState<boolean> | Whether the viewport is currently at the bottom |
following (expose) | ExposeState<ScrollEndFollowState> | Current end-follow state |
requestStatus (expose) | ExposeState<ScrollEndFollowRequestStatus> | Status of the latest end-follow request |
jumpToEnd() (expose) | () => void | Programmatically scroll to the end |
pauseFollowing() (expose) | () => ScrollSurfaceRequestOutcome | Pause automatic end-following |
| Prop / Expose | Type | Default |
|---|---|---|
size | 'icon' 'pill' | 'icon' |
disabled | boolean | false |
styleProfile | ShadcnStyleChoice | inherit → nearest scope → new-york-v4 |
atEnd (expose) | ExposeState<boolean> | Mirrored bottom state from Root |
newContentCount (expose) | ExposeState<number> | Mirrored new-content count from Root |