Chat Scroller
A stick-to-bottom message viewport. While you're near the bottom it follows new messages down; scroll up and it hands control back, surfacing a Jump to latest pill. Add a message below and watch it auto-follow — then scroll up first and add another.
Installation
Copy the piece into your app — it compiles with your build and the code is yours:
puzzle add piece chat-scroller
The scroller is the container; the message rows are your own markup — usually a loop of Chat Message rows. It owns only the scroll behavior, never the message data.
Usage
import ChatScroller from '@/components/ui/ChatScroller.pzl';
<ChatScroller height={ 360 } @pin={ setPinned }></ChatScroller>Pinning
Pinned means the viewport is scrolled within 40px of the bottom. While pinned, a ResizeObserver on the content watches for growth and keeps the newest message in view. Scroll up past the 40px band and pinning disengages: the auto-follow stops and the Jump to latest pill fades in. Clicking it smooth-scrolls to the bottom (instantly under prefers-reduced-motion) and re-pins.
// "Pinned" = within 40px of the bottom. Mirror it in the parent to drive
// UI like an unread badge.
events = {
setPinned: (isPinned) => this.setData({ pinned: isPinned }),
};
<ChatScroller @pin={ setPinned }> … </ChatScroller>@pin(isPinned) fires whenever the pinned state flips, so the parent can mirror it — e.g. a "N new messages" badge while the reader is scrolled up.
Accessibility
The viewport carries role="log", which implies aria-live="polite" — assistive tech announces messages as they're appended, without stealing focus. Give it a meaningful label (default "Messages") so the region is named. The Jump to latest pill is a real <button> with a visible focus ring, reachable by keyboard.