Message Scroller
A scroll container for chat messages with auto scroll and a scroll-to-end button.
shadcn/ui docsNew ChatHow can I help you today?
Installation
The component depends on the @shadcn/react package. Install it first:
pnpm add @shadcn/reactpnpm dlx shadcn@latest add https://neobrutalism.dev/r/message-scroller.jsonUsage
import {
MessageScrollerProvider,
MessageScroller,
MessageScrollerViewport,
MessageScrollerContent,
MessageScrollerItem,
MessageScrollerButton,
} from '@/components/ui/message-scroller'<MessageScrollerProvider>
<MessageScroller>
<MessageScrollerViewport>
<MessageScrollerContent>
{messages.map((message) => (
<MessageScrollerItem key={message.id} messageId={message.id}>
<Message>...</Message>
</MessageScrollerItem>
))}
</MessageScrollerContent>
</MessageScrollerViewport>
<MessageScrollerButton />
</MessageScroller>
</MessageScrollerProvider>The scroller needs a parent with a fixed height. Use the useMessageScroller hook inside the provider to scroll programmatically (scrollToEnd, scrollToStart, scrollToMessage).
Examples
Default
New ChatHow can I help you today?
Add Messages
New messages are scrolled into view automatically when the viewport is already at the end.
New ChatHow can I help you today?