A stick-to-bottom conversation viewport for streaming chat messages.
Put your messages in ChatConversation.Content and give the root a bounded height.
import {ChatConversation} from "@heroui-pro/react";
<ChatConversation>
<ChatConversation.Content>{/* ... */}</ChatConversation.Content>
<ChatConversation.ScrollButton /> {/* Optional */}
</ChatConversation>;Combine ChatConversation with ChatMessage, Reasoning, ChainOfThought, and PromptInput. Set aria-busy on the conversation while a reply streams.
Add ChatConversation.ScrollButton for a jump-to-bottom control. It shows only while the view is scrolled away from the bottom.
Call scrollToBottom from useChatConversation to bring back a reader who scrolled up, for example when they send a message. The view then follows new content again. Use the hook inside ChatConversation.
import {ChatConversation, useChatConversation} from "@heroui-pro/react";
import {useEffect} from "react";
function ScrollOnSend({lastMessage}: {lastMessage?: Message}) {
const {scrollToBottom} = useChatConversation();
useEffect(() => {
if (lastMessage?.role === "user") scrollToBottom();
}, [lastMessage, scrollToBottom]);
return null;
}
<ChatConversation aria-label="Conversation">
<ChatConversation.Content>{messages}</ChatConversation.Content>
<ScrollOnSend lastMessage={messages.at(-1)} />
</ChatConversation>;HeroUI follows the BEM methodology to ensure component variants and states are reusable and easy to customize.
The Chat Conversation component uses these CSS classes:
.chat-conversation: Scroll viewport.chat-conversation__content: Message column.chat-conversation__scroll-button-container: Sticky wrapper of the scroll button.chat-conversation__scroll-button: Scroll button.chat-conversation__scroll-anchor: Deprecated ScrollAnchor, an empty hidden div[data-state="visible|hidden"] on .chat-conversation__scroll-button-container: Whether the scroll button shows--chat-conversation-shadow-size: Height of the top and bottom fade (default: 32px)--chat-conversation-scrollbar-mask-size: Width kept clear of the fade for the scrollbar (default: 10px)The scroll container, with role="log", a polite live region. The view follows new content until the user scrolls up with a wheel, touch, or the keyboard, and follows again once they scroll back to the bottom. Supports native div props.
| Prop | Type | Default | Description |
|---|---|---|---|
initial | "instant" | "smooth" | "smooth" | Scroll behavior on mount |
resize | "instant" | "smooth" | "smooth" | Scroll behavior when content grows at the bottom |
The message column. It centers itself, so set its width with a class such as max-w-[714px]. Supports native div props.
Extends HeroUI Button props. Your onPress runs as well as the scroll. While hidden, it's disabled and hidden from screen readers.
| Prop | Type | Default | Description |
|---|---|---|---|
aria-label | string | "Scroll to bottom" | Accessible name of the icon button |
tooltip | ReactNode | - | Tooltip shown on hover and focus |
Reads the scroll state of the enclosing ChatConversation. It throws outside one.
const {hasOverflow, isAtBottom, scrollToBottom} = useChatConversation();| Property | Type | Description |
|---|---|---|
hasOverflow | boolean | Whether the content is taller than the view |
isAtBottom | boolean | Whether the view is at the bottom |
scrollToBottom | (behavior?: "instant" | "smooth") => void | Scrolls to the bottom and follows new content again. behavior defaults to smooth |
| API | Use instead |
|---|---|
ChatConversation.ScrollAnchor | Remove it; call scrollToBottom from useChatConversation to scroll |
If left in, ScrollAnchor renders an empty, hidden div with the .chat-conversation__scroll-anchor class. See v1.0.0 for the full migration.
aria-label, such as "Conversation".aria-busy={status === "streaming"} on the root so they can wait for the finished reply. Support varies between screen readers.Resources