# Message Scroller

A chat scroll container that anchors turns, opens saved transcripts, follows streamed responses, loads history without jumping, and jumps to any message.

Section: Blocks / Chat
Page: https://ui.heyramzi.com/components/message-scroller
Import path: `@heyramzi/ui/shadcn/message-scroller`

## Import

```ts
import * as Bubble from "@heyramzi/ui/shadcn/bubble";
import * as Message from "@heyramzi/ui/shadcn/message";
import * as MessageScroller from "@heyramzi/ui/shadcn/message-scroller";
import { Response } from "@heyramzi/ui/ai/response";
```

## Usage

```svelte
<MessageScroller.Provider>
  <MessageScroller.Root>
    <MessageScroller.Viewport>
      <MessageScroller.Content>
        {#each turns as turn (turn.id)}
          <MessageScroller.Item messageId={turn.id} scrollAnchor={turn.role === "user"}>
            {turn.text}
          </MessageScroller.Item>
        {/each}
      </MessageScroller.Content>
    </MessageScroller.Viewport>
    <MessageScroller.Button />
  </MessageScroller.Root>
</MessageScroller.Provider>
```

## Demo

```svelte
<!-- Ours, not upstream's: theirs streams through @ai-sdk/svelte and docs-only helpers this package doesn't ship. -->
<script lang="ts">
	import * as Bubble from "@heyramzi/ui/shadcn/bubble";
	import * as Message from "@heyramzi/ui/shadcn/message";
	import * as MessageScroller from "@heyramzi/ui/shadcn/message-scroller";
	import { Response } from "@heyramzi/ui/ai/response";

	const turns = [
		{ id: "q1", role: "user", text: "How should I clean up our beam effects?" },
		{
			id: "a1",
			role: "assistant",
			text: "Here is the plan:\n\n1. **Extract** the beam into the shared package\n2. **Showcase** it on the Effects page\n3. **Migrate** both apps onto the shared copy",
		},
		{ id: "q2", role: "user", text: "And the old copies?" },
		{ id: "a2", role: "assistant", text: "Delete them in the same change, so nothing imports the stale one." },
	] as const;
</script>

<div class="h-68 w-full max-w-md">
	<MessageScroller.Provider>
		<MessageScroller.Root>
			<MessageScroller.Viewport>
				<MessageScroller.Content class="gap-4 p-1">
					{#each turns as turn (turn.id)}
						{@const user = turn.role === "user"}
						<MessageScroller.Item messageId={turn.id} scrollAnchor={user}>
							<Message.Root align={user ? "end" : "start"}>
								<Message.Content>
									<Bubble.Root variant={user ? "default" : "muted"} align={user ? "end" : "start"}>
										<Bubble.Content>
											{#if user}{turn.text}{:else}<Response content={turn.text} />{/if}
										</Bubble.Content>
									</Bubble.Root>
								</Message.Content>
							</Message.Root>
						</MessageScroller.Item>
					{/each}
				</MessageScroller.Content>
			</MessageScroller.Viewport>
			<MessageScroller.Button />
		</MessageScroller.Root>
	</MessageScroller.Provider>
</div>
```

## API

### MessageScroller.Provider

Every prop of `MessageScroller.Provider` from `@shadcn-svelte/primitives/message-scroller`.

### MessageScroller.Root

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `class` | `string` |  |  |
| `ref` | `HTMLElement \| null` | `null` | bindable |

Every prop of `MessageScroller.Root` from `@shadcn-svelte/primitives/message-scroller`.

### MessageScroller.Viewport

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `class` | `string` |  |  |
| `ref` | `HTMLElement \| null` | `null` | bindable |

Every prop of `MessageScroller.Viewport` from `@shadcn-svelte/primitives/message-scroller`.

### MessageScroller.Content

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `ref` | `HTMLElement \| null` | `null` | bindable |
| `class` | `string` |  |  |

Every prop of `MessageScroller.Content` from `@shadcn-svelte/primitives/message-scroller`.

### MessageScroller.Item

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `ref` | `HTMLElement \| null` | `null` | bindable |
| `class` | `string` |  |  |
| `scrollAnchor` | `boolean` | `false` |  |

Every prop of `MessageScroller.Item` from `@shadcn-svelte/primitives/message-scroller`.

### MessageScroller.Button

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `variant` | `"default"` \| `"outline"` \| `"ghost"` \| `"destructive"` \| `"text"` \| `"dashed"` | `"outline"` |  |
| `size` | `"sm"` \| `"default"` \| `"lg"` | `"sm"` |  |
| `label` | `string` |  | What a screen reader calls the icon-only button, in the app's language. Defaults to "Scroll to end", or "Scroll to start" when `direction="start"`. |
| `ref` | `HTMLElement \| null` | `null` | bindable |
| `direction` | `string` | `"end"` |  |
| `class` | `string` |  |  |
| `children` | `Snippet` |  |  |
| `child` | `Snippet` |  |  |
| `onclick` |  |  |  |

Every prop of `MessageScroller.Button` from `@shadcn-svelte/primitives/message-scroller`.
