Skip to content
h v3.13.3
Search the docs
Find a component, section or page.

Message Scroller

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

How should I clean up our beam effects?

Here is the plan:

  1. Extract the beam into the shared package
  2. Showcase it on the Effects page
  3. Migrate both apps onto the shared copy
And the old copies?

Delete them in the same change, so nothing imports the stale one.

Installation

pnpm add @heyramzi/ui

Usage

import * as MessageScroller from "@heyramzi/ui/shadcn/message-scroller";
<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>

Keyboard and accessibility

Key Does
Tab Moves focus to the thread, then to the scroll button when it shows.
Arrow Up Arrow Down PageUp PageDown Home End Scrolls the thread and stops it following new messages.
Space Enter On the scroll button, jumps to the end.
  • The thread is a region named "Messages" that takes focus. Rename it with `aria-label` on the viewport.
  • The message list is a log, so new messages are read out as they arrive.
  • The scroll button is named "Scroll to end" or "Scroll to start", or whatever its `label` says.
  • After the jump the button hides and focus moves to the thread.

API reference

MessageScroller.Provider

...rest
Every prop of MessageScroller.Provider from @shadcn-svelte/primitives/message-scroller
Prop Type Default
...rest Every prop of MessageScroller.Provider from @shadcn-svelte/primitives/message-scroller

MessageScroller.Root

class string
ref bindable HTMLElement | null
Default null
...rest
Every prop of MessageScroller.Root from @shadcn-svelte/primitives/message-scroller
Prop Type Default
class string
ref bindable HTMLElement | null null
...rest Every prop of MessageScroller.Root from @shadcn-svelte/primitives/message-scroller

MessageScroller.Viewport

class string
ref bindable HTMLElement | null
Default null
...rest
Every prop of MessageScroller.Viewport from @shadcn-svelte/primitives/message-scroller
Prop Type Default
class string
ref bindable HTMLElement | null null
...rest Every prop of MessageScroller.Viewport from @shadcn-svelte/primitives/message-scroller

MessageScroller.Content

ref bindable HTMLElement | null
Default null
class string
...rest
Every prop of MessageScroller.Content from @shadcn-svelte/primitives/message-scroller
Prop Type Default
ref bindable HTMLElement | null null
class string
...rest Every prop of MessageScroller.Content from @shadcn-svelte/primitives/message-scroller

MessageScroller.Item

ref bindable HTMLElement | null
Default null
class string
scrollAnchor boolean
Default false
...rest
Every prop of MessageScroller.Item from @shadcn-svelte/primitives/message-scroller
Prop Type Default
ref bindable HTMLElement | null null
class string
scrollAnchor boolean false
...rest Every prop of MessageScroller.Item from @shadcn-svelte/primitives/message-scroller

MessageScroller.Button

variant "default" | "outline" | "ghost" | "destructive" | "text" | "dashed"
Default "outline"
size "sm" | "default" | "lg"
Default "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 bindable HTMLElement | null
Default null
direction string
Default "end"
class string
children Snippet
child Snippet
onclick MessageScroller.Button
...rest
Every prop of MessageScroller.Button from @shadcn-svelte/primitives/message-scroller
Prop Type Default
variant "default" | "outline" | "ghost" | "destructive" | "text" | "dashed" "outline"
size "sm" | "default" | "lg" "sm"
label

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"`.

string
ref bindable HTMLElement | null null
direction string "end"
class string
children Snippet
child Snippet
onclick MessageScroller.Button
...rest Every prop of MessageScroller.Button from @shadcn-svelte/primitives/message-scroller