# Jump to latest

> A chat that follows the answer as it streams, lets go the moment you scroll up, and brings you back.

Every chat needs this, and most get it wrong: they drag you back down while you read, or leave you stranded mid-answer. This scroll area stays pinned to the bottom while text streams in, and lets go the instant you reach for the wheel, trackpad, touch or keyboard. While you’re away a round ↓ button waits; when new text lands below, it widens into "● Writing" under a sweep of light, and when the answer ends the words morph into "New reply" as the pill eases to fit. Click it and the chat glides down, chasing the moving bottom, and starts following again.

## Install

```bash
npx shadcn@latest add https://hairlineui.com/r/chat-scroll.json
```

Needs React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.

- npm: `lucide-react`
- Hairline UI components it needs (the CLI installs them too): `text-morph`
- Docs and live preview: https://hairlineui.com/ui/chat-scroll
- Registry item (source): https://hairlineui.com/r/chat-scroll.json

## Usage

```tsx
import { ChatScroll } from "@/components/chat-scroll";

<ChatScroll streaming={busy} followKey={lastUserMessageId} className="flex-1" contentClassName="mx-auto max-w-2xl px-4 py-6">
  {messages.map(renderMessage)}
</ChatScroll>
```

## With the AI SDK

```tsx
"use client";
import { useChat } from "@ai-sdk/react";
import { ChatScroll } from "@/components/chat-scroll";

export function Conversation() {
  const { messages, status } = useChat();
  const lastUser = messages.findLast((m) => m.role === "user");

  return (
    <ChatScroll
      streaming={status === "streaming"}
      followKey={lastUser?.id} // sending a message brings the person back down
      className="h-full"
      contentClassName="mx-auto flex max-w-2xl flex-col gap-6 px-4 py-6"
    >
      {messages.map((m) => (
        <Message key={m.id} message={m} />
      ))}
    </ChatScroll>
  );
}
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `ReactNode` | – | The messages. |
| `streaming` | `boolean` | `false` | While true, the button says "Writing" with a pulsing dot. |
| `followKey` | `string \| number` | – | Change it, e.g. to the latest user message id, to glide back to the bottom. |
| `threshold` | `number` | `48` | How close to the bottom (px) still counts as at the bottom. |
| `className / contentClassName` | `string` | – | Give the area a height (or flex-1); style the inner column. |

## States

- **following**: At the bottom: new content keeps the latest line in view, with no visible jumps.
- **away**: You scrolled up: it stops following immediately and a round ↓ button fades up.
- **new below**: Content arrived while you were away: the button widens (380ms) into a pulsing "Writing" while streaming; when it ends, "Writing" morphs into "New reply" and the pulse settles.
- **back**: The button glides to the bottom, re-reading it each frame, and following resumes. Changing followKey does the same.

## What it handles

Every chat needs this and most get it wrong: they drag the reader back down while they are reading, or leave them stranded in the middle of an answer.

- **It follows the answer**: While you are at the bottom, new text keeps the latest line in view.
- **It lets go at once**: The first upward wheel, touch drag, Page Up, Up arrow or Home stops it following, before the next line can pull you back.
- **A button waits for you**: A round ↓ button appears and widens to “Writing” while text arrives, then reads “New reply” when it ends.
- **It glides back**: Click and the chat glides down, chasing the moving bottom, and starts following again.
- **Late content is handled**: Images and code blocks that load after the text no longer push the reader off the bottom.
- **Keyboard friendly**: The area is focusable so the keyboard can scroll it, and the button says what is waiting.

## Replaces

scrollIntoView on every message, scroll position checks, a jump-to-bottom button, wheel and touch listeners, a ResizeObserver

## Where it fits

- **AI chat windows**: Follow the answer as it streams in, without fighting the reader.
- **Agent transcripts**: Long-running agent output that people check on now and then.
- **Support chat widgets**: Keep the newest message in view and show when a reply arrived below.
- **Message feeds**: Team chat or comment threads where new items land at the bottom.

## Notes

- It lets go on the first upward wheel, touch drag, Page Up, Up arrow or Home, before the next frame of text can pull the reader back.
- The area is focusable, so the keyboard can scroll it; the button names what is waiting ("Still writing below. Jump to latest").
- Following uses a ResizeObserver on the content, so images and code blocks that load late are handled too.
- Installs Text morph. With reduced motion, the jump is instant and the button and its words simply change.

License: MIT (https://hairlineui.com/license#components)
