Thread
Slant / People & chat
A chat log of user and assistant messages.
Demo
Usage
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
| Prop | Type | Default | Description |
|---|---|---|---|
label | string | — | The log's accessible name. |
autoScroll | boolean | true | Keeps 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. |
maxHeight | number | 210 | The height in pixels at which the log starts to scroll. |
jumpToLatest | boolean | true | Shows 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. |
jumpLabel | string | messages.jumpToLatest | The jump button's text. |
…rest | HTMLAttributes | — | 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
| Tab | focuses the log, then the Jump to latest button while it shows |
| ↑ / ↓ | scrolls the log a line at a time |
| PageUp / PageDown | scrolls it a screen at a time |
| Home / End | jumps to the oldest or the newest message |
| Enter / Space | on Jump to latest: scrolls to the newest message and puts focus back on the log |
Accessibility
- The log has
role="log"andaria-live="polite", named bylabel, so screen readers read new messages when they arrive without cutting in. - It is in the tab order (
tabIndex0), 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.