GitHubX

Chat Message Area

PreviousNext

A component that adds auto scrolling functionality to a list of messages.

The Chat Message Area component provides a responsive and intelligent scrollable container specifically designed for streaming interfaces. It features a sophisticated auto-scrolling system that adapts to user interaction:

  • Smart Auto-scroll: Automatically scrolls to new messages when they appear, but only if the user is already at the bottom
  • Interaction Awareness: Auto-scroll automatically disables when users scroll up to read previous messages
  • Re-engagement: Auto-scroll re-enables when users manually scroll back to the bottom
  • Mobile Optimized: On touch devices, auto-scroll pauses while the user's finger is on the screen
  • Convenient Navigation: Includes a scroll-to-bottom button that appears when not at the bottom

About

This component is built on top of use-stick-to-bottom, a React hook that provides smooth auto-scrolling functionality for chat interfaces and streaming content.

Installation

pnpm dlx shadcn@latest add @simple-ai/chat-message-area

Usage

import {
  ChatMessageArea,
  ChatMessageAreaContent,
  ChatMessageAreaScrollButton,
} from "@/components/ui/chat-message-area"
<ChatMessageArea>
  <ChatMessageAreaContent className="px-4 py-8 space-y-4">
    {/* Your messages go here */}
  </ChatMessageAreaContent>
  <ChatMessageAreaScrollButton />
</ChatMessageArea>

Examples

Alignment

You can align the scroll button to the left, right, or center using the alignment prop on ChatMessageAreaScrollButton.

Streaming

Try out the auto-scrolling behavior in this live demo. Scroll up to pause auto-scrolling, scroll to bottom to re-enable it, or use the scroll button for quick navigation. On mobile, touch the screen to temporarily pause auto-scroll.