ChatConversation
Scrollable chat viewport that follows streaming messages
Usage
import {ChatConversation} from "@peakui-pro/react";Anatomy
import {ChatConversation} from "@peakui-pro/react";
export default () => (
// The viewport scrolls inside a bounded height: `flex-1` in a flex column, or `h-full`.
<ChatConversation className="flex-1">
{/* Required for following: the root watches this part grow. */}
<ChatConversation.Content>{messages}</ChatConversation.Content>
{/* Optional: a styling and testing hook; following does not depend on it. */}
<ChatConversation.ScrollAnchor />
{/* Optional: always mounted, shown only away from the bottom. */}
<ChatConversation.ScrollButton />
</ChatConversation>
);Examples
Full Chat
Compose the conversation with a reasoning trace and a prompt input.
Scroll Button
Add ScrollButton for an explicit jump-to-bottom control.
Streaming
Follows appended content at the bottom and holds still once the reader scrolls up.
Short Content
Keeps the button hidden while the content fits the viewport.
Switching Conversations
key the root per conversation: a released viewport stays released across a content swap.
Accessible Names
aria-label names each root; the default name is the same for every one.
Focusable Messages
tabIndex={-1} removes the viewport from the tab order when messages hold focusable content.
Quiet Log
aria-live="off" stops the log announcing additions, the scroll button included.
Customization
Tailwind CSS
<ChatConversation className="[--chat-conversation-content-max-width:48rem] [--chat-conversation-anchor-threshold:48px]">
<ChatConversation.Content>{messages}</ChatConversation.Content>
<ChatConversation.ScrollButton className="shadow-overlay" />
</ChatConversation>Global CSS
@layer components {
.chat-conversation {
--chat-conversation-content-max-width: 48rem;
--chat-conversation-content-gap: 1.5rem;
--chat-conversation-scroll-button-offset: 1.5rem;
--chat-conversation-anchor-threshold: 48px;
}
.chat-conversation__scroll-button {
@apply shadow-overlay;
}
}Styling Reference
PeakUI follows the BEM methodology, so variants and states are plain class names you can target.
CSS Classes
The ChatConversation component uses these CSS classes (view source styles):
Base Classes
.chat-conversation- Scrolling viewport
Element Classes
.chat-conversation__content- Centered message column.chat-conversation__scroll-anchor- One-pixel marker at the foot of the content.chat-conversation__scroll-button-container- Sticky, zero-height positioner of the button.chat-conversation__scroll-button- Jump-to-bottom button, beside the core.buttonclasses
Slots
[data-slot="chat-conversation"][data-slot="chat-conversation-content"][data-slot="chat-conversation-scroll-anchor"][data-slot="chat-conversation-scroll-button-container"][data-slot="chat-conversation-scroll-button"]
CSS Variables
| Variable | Purpose |
|---|---|
--chat-conversation-content-max-width | Widest the message column grows; defaults to calc(var(--spacing) * 178.5) |
--chat-conversation-content-gap | Space between messages; defaults to calc(var(--spacing) * 8) |
--chat-conversation-content-padding-block | Space above the first and below the last message; defaults to calc(var(--spacing) * 8) |
--chat-conversation-content-padding-inline | Space beside the column; defaults to calc(var(--spacing) * 4) |
--chat-conversation-scroll-button-offset | Distance from the foot of the viewport to the foot of the button; defaults to calc(var(--spacing) * 4) |
--chat-conversation-anchor-threshold | How far from the bottom the reader still counts as at the bottom; read in script, so a px, rem or em length, never a calc(); defaults to 24px |
Interactive States
The viewport takes focus so the keyboard can scroll it:
- Focus:
:focus-visibledraws a ring inside the edge - Attached:
[data-state="attached"]on the anchor while the viewport follows new content - Released:
[data-state="released"]on the anchor after an upward scroll past the threshold - Button hidden:
[data-state="hidden"]on the button container, witharia-hidden, a disabled button andvisibility: hidden - Button shown:
[data-state="visible"]on the button container - Reduced motion:
@media (prefers-reduced-motion: reduce)ends the fade and scrolls to the bottom at once - Forced colors:
@media (forced-colors: active)draws the focus ring inHighlight
API Reference
ChatConversation
| Prop | Type | Default | Description |
|---|---|---|---|
aria-label | string | "Conversation" | Accessible name of the log. The default is the same for every root, so name each conversation when a page holds more than one |
role | string | "log" | A streamed answer is announced as it grows |
tabIndex | number | 0 | A scrollable region must be reachable by keyboard; pass -1 when the messages hold focusable content |
aria-live | 'off' | 'polite' | 'assertive' | "polite" (from role="log") | The scroll button sits inside the log, so showing it adds it to the log; "off" silences additions, new messages included |
key | React.Key | - | Set it per conversation: a released viewport stays released when only Content is swapped |
className | string | - | Additional classes |
render | DOMRenderFunction<'div', undefined> | - | Replaces the rendered <div> with your own element |
...rest | ComponentProps<'div'> | - | Native <div> attributes |
ChatConversation.Content
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | - | Additional classes |
render | DOMRenderFunction<'div', undefined> | - | Replaces the rendered <div> with your own element |
...rest | ComponentProps<'div'> | - | Native <div> attributes. The root follows growth of this part only: messages placed directly in the root are not followed |
ChatConversation.ScrollAnchor
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | - | Additional classes |
render | DOMRenderFunction<'div', undefined> | - | Replaces the rendered <div> with your own element |
...rest | ComponentProps<'div'> | - | Native <div> attributes. aria-hidden="true" is always set; data-state is "attached" or "released" |
ChatConversation.ScrollButton
| Prop | Type | Default | Description |
|---|---|---|---|
children | React.ReactNode | (values: ButtonRenderProps) => React.ReactNode | An arrow-down icon | Replaces the default glyph |
aria-label | string | "Scroll to bottom" | Accessible name. The default applies to any icon-only button |
isIconOnly | boolean | true | Square button for one icon; set false to show text beside it |
variant | 'primary' | 'secondary' | 'tertiary' | 'outline' | 'ghost' | 'danger' | 'danger-soft' | 'secondary' | Core button style |
size | 'sm' | 'md' | 'lg' | 'sm' | Core button size |
isDisabled | boolean | false | Whether the button is disabled; it is always disabled while the viewport is at the bottom |
onPress | (e: PressEvent) => void | - | Handler called before the viewport scrolls to the bottom, smoothly or at once under reduced motion |
className | string | (values: ButtonRenderProps) => string | - | Additional classes, or a function of the button's state |
render | DOMRenderFunction<'button', ButtonRenderProps> | - | Replaces the rendered element; receives the props with data-slot set |
...rest | ButtonProps | - | Every other core Button prop |
Render Props
| Prop | Type | Description |
|---|---|---|
isPending | boolean | Whether the button is waiting on an operation |
isPressed | boolean | Whether the button is currently pressed |
isHovered | boolean | Whether the button is hovered |
isFocused | boolean | Whether the button is focused |
isFocusVisible | boolean | Whether the button is focused by keyboard |