Jump to LatestPRO
A floating pill that counts new messages while you're scrolled up and takes you back down.
Code
2 files · 242 lines of TypeScriptPRO
Jump to Latest is part of Pro
Get its source, the one-paste agent prompt and all 113 components, for a one-time $99.
Motion notes
- The pill rises in from a soft blur and leaves downward, in the direction the view is about to travel. It leaves on click, not when the scroll lands, so the response feels immediate.
- The unread count rolls digit by digit, and the arrow nudges down once per new message, pointing at what just arrived without looping for attention.
- useStickToBottom follows new content instantly while you're at the bottom, so streaming text never drifts out of view, and lets go the moment you scroll up. Any wheel, touch or key input cancels a jump in flight.
- With reduced motion, the pill fades without travel or blur, the count changes in place, and jumping scrolls instantly instead of smoothly.
Usage
Example
const ref = useRef<HTMLDivElement>(null);
const { isAtBottom, unread, scrollToBottom } = useStickToBottom(ref, { count: messages.length });
<div className="relative h-full">
<div ref={ref} className="h-full overflow-y-auto">
{messages.map((m) => <ChatMessage key={m.id} {...m} />)}
</div>
<div className="pointer-events-none absolute inset-x-0 bottom-4 flex justify-center">
<ScrollToBottom
visible={!isAtBottom}
count={unread}
onClick={() => scrollToBottom()}
className="pointer-events-auto"
/>
</div>
</div>Props
| Prop | Type | Default | Description |
|---|---|---|---|
| visible | boolean | — | Usually !isAtBottom from useStickToBottom. |
| count | number | 0 | Unread messages below. 0 shows “Jump to latest”. |
| onClick | () => void | — | Usually scrollToBottom from useStickToBottom. |
| className | string | — | Classes for the pill. Position it yourself, e.g. in an absolute, centered wrapper. |
| useStickToBottom(ref, options) | { threshold?: number; count?: number } => { isAtBottom, unread, scrollToBottom } | — | Pins the scroll container to its newest content until the user scrolls away. Pass the total message count to get unread. Starts scrolled to the bottom. |