Thread

Slant / People & chat

A chat log of user and assistant messages.

Demo

Assistant

Usage

@tuttn/slant
import { Message, Thread } from '@tuttn/slant'

// The log scrolls itself, never the page. It follows new messages while the
// reader is at the bottom; a reader who scrolled up to read back stays put,
// with a Jump to latest button over the log's foot to take them back.
<Thread label="Conversation" maxHeight={240}>
  {lines.map(line => <Message key={line.id} author={line.author}>{line.text}</Message>)}
  {typing && <Message author="assistant" typing />}
</Thread>

// autoScroll={false} never moves the reader; jumpToLatest={false} drops the button.
<Thread label="Transcript" autoScroll={false} jumpToLatest={false}>{messages}</Thread>

// jumpLabel renames the button for one log.
<Thread label="Conversation" jumpLabel="New messages">{messages}</Thread>

Props

PropTypeDefaultDescription
labelstring—The log's accessible name.
autoScrollbooleantrueKeeps the newest message in view when the children change, but only for a reader already at the bottom (within 24px). A reader who scrolled up to read back stays where they are.
maxHeightnumber210The height in pixels at which the log starts to scroll.
jumpToLatestbooleantrueShows a Jump to latest button over the log's foot while the reader is scrolled up from the newest message (more than 24px from the bottom). Pressing it scrolls the log to the bottom and moves focus to the log. The button sits beside the log, never inside its live region.
jumpLabelstringmessages.jumpToLatestThe jump button's text.
…restHTMLAttributes—className, style, onScroll, the ref and other attributes reach the log <div>. tabIndex is 0 unless you pass another. The log sits in a <div class="sl-thread-frame">, which holds the jump button; to size the thread in a flex or grid layout, style that wrapper.

Keyboard

Tabfocuses the log, then the Jump to latest button while it shows
↑ / ↓scrolls the log a line at a time
PageUp / PageDownscrolls it a screen at a time
Home / Endjumps to the oldest or the newest message
Enter / Spaceon Jump to latest: scrolls to the newest message and puts focus back on the log

Accessibility

  • The log has role="log" and aria-live="polite", named by label, so screen readers read new messages when they arrive without cutting in.
  • It is in the tab order (tabIndex 0), so keyboard users can scroll it with the browser’s own keys.
  • It follows new messages only for a reader at the bottom (within 24px). Anyone who scrolled up to read back keeps their place until they scroll down again.
  • Jump to latest shows only while the reader is scrolled up, and stays while new messages arrive below. It is the log’s sibling, outside the live region, so its coming and going is never announced. Pressing it moves focus to the log, because the button goes once the log reaches the bottom.
  • Keep the composer outside the log, with a labelled field and send button, as the demo does.

Motion

Jump to latest scrolls smoothly, or at once when the reader prefers reduced motion, and the button rises in with the same short entrance as the messages, which reduced motion also removes.

Server rendering

The button is hidden in the server’s HTML and the first client frame; the log measures where the reader is after it mounts, so hydration always matches.

Full source