Skip to content
Haze UI

Message scroller

A chat transcript that follows new messages, with sticky day pills, a New messages divider and a Jump to latest button with a count.

pnpm dlx shadcn@latest add @haze/message-scroller
Open preview in a new tab
Livesmall script

When to use

  • A transcript or log grows while the reader may be reading older rows, such as an assistant chat
  • Messages arrive live and the view should stay put if the reader scrolled up
  • Older rows load above the current ones and the visible position must not jump

When not to use

  • The whole page is the conversation and scrolls with the window. Use chat-thread.
  • The content is a static long article with a table of contents. Use scroll-area or toc-progress.

Installation

Add the Haze registry to components.json once, then install Message scroller with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.

pnpm dlx shadcn@latest add @haze/message-scroller
First time? Registry and theme setup

1. Add to components.json:

{
  "registries": {
    "@haze": "http://localhost:4329/r/{name}.json"
  }
}

2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";

API reference

PropTypeDefaultDescription
id*string–Id of the scroll region. The end marker is <id>-end and the jump link points at it.
heightstring"h-72"Height utility class of the scroll region.
labelstring"Conversation"Accessible name of the scroll region.
jumpLabelstring"Jump to latest"Text of the jump control.
newLabelstring"new"Word after the unread count on the jump button, such as "2 new".
unreadLabelstring"New messages"Text of the divider the script inserts above the first unread row when messages arrive while the reader is scrolled up.
announceLabelstring"new messages below"Screen-reader text after the count when messages arrive while the reader is scrolled up.
livebooleantrueWhile the reader follows the end, announce new rows in the polite status line ("2 new messages"), debounced to about one second.
liveOnestring"new message"Singular text after the count in the following announcement.
liveManystring"new messages"Plural text after the count in the following announcement.
classstring–Extra classes on the wrapper.
default slotrows–One direct child per message. Append or prepend direct children to update the transcript. To group by day, wrap a day in a [data-ms-day] element whose first child is a [data-ms-date] pill; the pill sticks to the top while that day scrolls. A [data-ms-unread] child marks a New messages divider (a flex row with a span), and the script adds one itself for rows that arrive while scrolled up.
earlier slotnode–Optional control pinned to the top of the scroll, such as a Load earlier button.

Keyboard interactions

Tab
Focus the scroll region, then the Jump to latest control.
Arrow UpDown, Page UpDown, HomeEnd
Scroll the focused region.
Enter
On Jump to latest: scroll to the newest message and resume following.

Accessibility

  • The scroller is a focusable region with a label, not role="log": a live log would read every row aloud, including the ones the reader scrolled up to see. Rows keep their own sender text.
  • A polite status line announces only the count of new messages. Scrolled up: "2 new messages below". Following the end (live, on by default): "2 new messages", debounced to about one second so a burst is one line, never repeated when identical in a row, and cleared a few seconds later. Set live to false when the rows announce themselves.
  • Without script the region scrolls normally and a Jump to latest link points at the end marker. With script the link becomes a button shown only when the reader is away from the end.
  • When the jump button hides itself after use, focus moves to the scroll region so keyboard users keep their place.
  • The date pills and the divider are plain text, readable in order. The divider fades out about two seconds after the reader is back at the end; the Jump to latest button rises in and its count reads "3 new".
  • Smooth scrolling is replaced by an instant jump under prefers-reduced-motion.

Notes for AI

Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.

  • Install and use

    Install the Haze UI component "Message scroller" with `npx shadcn@latest add @haze/message-scroller`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import MessageScroller from "@/components/haze/ui/message-scroller.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/ui/message-scroller.md

  • Customize with real content

    Adapt the Haze message-scroller ui for our product. Replace the demo values of these props with our real content: id, height, label, jumpLabel, newLabel, unreadLabel, announceLabel, live, liveOne, liveMany, class, default slot, earlier slot. Keep the layout, the heading level rules and these accessibility details: The scroller is a focusable region with a label, not role="log": a live log would read every row aloud, including the ones the reader scrolled up to see. Rows keep their own sender text. A polite status line announces only the count of new messages. Scrolled up: "2 new messages below". Following the end (live, on by default): "2 new messages", debounced to about one second so a burst is one line, never repeated when identical in a row, and cleared a few seconds later. Set live to false when the rows announce themselves. Without script the region scrolls normally and a Jump to latest link points at the end marker. With script the link becomes a button shown only when the reader is away from the end. When the jump button hides itself after use, focus moves to the scroll region so keyboard users keep their place. The date pills and the divider are plain text, readable in order. The divider fades out about two seconds after the reader is back at the end; the Jump to latest button rises in and its count reads "3 new". Smooth scrolling is replaced by an instant jump under prefers-reduced-motion. Do not add raw color classes; use the Haze tokens.

  • Choose the right block

    Before using message-scroller, check it fits: use it when a transcript or log grows while the reader may be reading older rows, such as an assistant chat; messages arrive live and the view should stay put if the reader scrolled up; older rows load above the current ones and the visible position must not jump. Avoid it when the whole page is the conversation and scrolls with the window. use chat-thread.; the content is a static long article with a table of contents. use scroll-area or toc-progress.. Alternatives: @haze/chat-thread, @haze/scroll-area, @haze/log-viewer, @haze/scroll-progress.

Dependencies

  • npm: @lucide/astro
  • @haze/utils
  • @haze/theme (one-time setup)

Source · Original Haze UI work.

Catalog

↑↓ moveEnter openEsc close

Keyboard shortcuts

CtrlK
Command palette
/
Focus search
←↑→↓
Move between cards
jk
Next / previous card
ci
Copy code / install command (detail page)
[]
Previous / next entry
?
This help
Esc
Close dialog