Message Scroller
The scrolling chat list. It stays on the newest message while you're at the bottom, stops following when you scroll up to read, and shows a "Jump to latest" button when there's more below. Same markup and props in every style: switch the style in the header to see it change.
Basic
A conversation of bubbles that opens at the newest message. Scroll up and the jump button appears. In HTML, add data-vin-message-scroller.
<div class="vin-message-scroller vin-message-scroller--outline" data-vin-message-scroller style="width: 100%; max-width: 460px; height: 320px">
<div class="vin-message-scroller__viewport" role="log" aria-live="polite" aria-label="Conversation" tabindex="0">
<div class="vin-message-scroller__content">
<div class="vin-bubble-group">
<p class="vin-bubble vin-bubble--user">I'm going to Lisbon in March. Any tips?</p>
<p class="vin-bubble">March is lovely there: mild, and fewer crowds than summer. Bring good shoes, the hills are steep.</p>
<p class="vin-bubble vin-bubble--user">Where should I stay?</p>
<p class="vin-bubble">Alfama for old streets and views, Chiado for shops and cafés, or Príncipe Real if you want somewhere quieter.</p>
<p class="vin-bubble vin-bubble--user">How do I get from the airport?</p>
<p class="vin-bubble">The metro's red line goes straight to the city in about 25 minutes. A taxi takes 15 to 20 minutes.</p>
<p class="vin-bubble vin-bubble--user">Is a day trip to Sintra worth it?</p>
<p class="vin-bubble">Yes. Take the train from Rossio, go early, and book Pena Palace tickets ahead.</p>
</div>
</div>
</div>
<button type="button" class="vin-btn vin-btn--secondary vin-btn--sm vin-message-scroller__jump" hidden><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 5v14"/><path d="m19 12-7 7-7-7"/></svg>Jump to latest</button>
</div>import { MessageScroller } from "@/components/vin/message-scroller";
import { Bubble, BubbleGroup } from "@/components/vin/bubble";
const chat: [from: "user" | "assistant", text: string][] = [
["user", "I'm going to Lisbon in March. Any tips?"],
["assistant", "March is lovely there: mild, and fewer crowds than summer. Bring good shoes, the hills are steep."],
["user", "Where should I stay?"],
["assistant", "Alfama for old streets and views, Chiado for shops and cafés, or Príncipe Real if you want somewhere quieter."],
["user", "How do I get from the airport?"],
["assistant", "The metro's red line goes straight to the city in about 25 minutes. A taxi takes 15 to 20 minutes."],
["user", "Is a day trip to Sintra worth it?"],
["assistant", "Yes. Take the train from Rossio, go early, and book Pena Palace tickets ahead."],
];
export function MessageScrollerBasic() {
return (
<MessageScroller outline style={{ width: "100%", maxWidth: 460, height: 320 }}>
<BubbleGroup>
{chat.map(([from, text], i) => <Bubble as="p" from={from} key={i}>{text}</Bubble>)}
</BubbleGroup>
</MessageScroller>
);
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import MessageScroller from "@/components/vin/message-scroller.vue";
import Bubble, { BubbleGroup } from "@/components/vin/bubble.vue";
const chat: ["user" | "assistant", string][] = [
["user", "I'm going to Lisbon in March. Any tips?"],
["assistant", "March is lovely there: mild, and fewer crowds than summer. Bring good shoes, the hills are steep."],
["user", "Where should I stay?"],
["assistant", "Alfama for old streets and views, Chiado for shops and cafés, or Príncipe Real if you want somewhere quieter."],
["user", "How do I get from the airport?"],
["assistant", "The metro's red line goes straight to the city in about 25 minutes. A taxi takes 15 to 20 minutes."],
["user", "Is a day trip to Sintra worth it?"],
["assistant", "Yes. Take the train from Rossio, go early, and book Pena Palace tickets ahead."],
];
</script>
<template>
<MessageScroller outline style="width: 100%; max-width: 460px; height: 320px">
<BubbleGroup>
<Bubble v-for="([from, text], i) in chat" :key="i" as="p" :from="from">{{ text }}</Bubble>
</BubbleGroup>
</MessageScroller>
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import MessageScroller from "$lib/components/vin/message-scroller.svelte";
import Bubble from "$lib/components/vin/bubble.svelte";
import BubbleGroup from "$lib/components/vin/bubble-group.svelte";
const chat: [from: "user" | "assistant", text: string][] = [
["user", "I'm going to Lisbon in March. Any tips?"],
["assistant", "March is lovely there: mild, and fewer crowds than summer. Bring good shoes, the hills are steep."],
["user", "Where should I stay?"],
["assistant", "Alfama for old streets and views, Chiado for shops and cafés, or Príncipe Real if you want somewhere quieter."],
["user", "How do I get from the airport?"],
["assistant", "The metro's red line goes straight to the city in about 25 minutes. A taxi takes 15 to 20 minutes."],
["user", "Is a day trip to Sintra worth it?"],
["assistant", "Yes. Take the train from Rossio, go early, and book Pena Palace tickets ahead."],
];
</script>
<MessageScroller outline style="width: 100%; max-width: 460px; height: 320px">
<BubbleGroup>
{#each chat as [from, text], i (i)}<Bubble as="p" {from}>{text}</Bubble>{/each}
</BubbleGroup>
</MessageScroller>With messages
Messages and a typing bubble at the end. New messages keep it pinned while you're at the bottom.
<div class="vin-message-scroller vin-message-scroller--outline" data-vin-message-scroller style="width: 100%; max-width: 560px; height: 360px">
<div class="vin-message-scroller__viewport" role="log" aria-live="polite" aria-label="Chat with the assistant" tabindex="0">
<div class="vin-message-scroller__content">
<article class="vin-message vin-message--end">
<div class="vin-message__body">
<div class="vin-message__content"><p class="vin-bubble vin-bubble--user">Write a haiku about code review.</p></div>
</div>
</article>
<article class="vin-message">
<div class="vin-message__avatar" aria-hidden="true">
<span class="vin-avatar vin-avatar--sm vin-avatar--square" role="img" aria-label="Assistant"><span class="vin-avatar__fallback">AI</span></span>
</div>
<div class="vin-message__body">
<header class="vin-message__header"><p class="vin-message__author">Assistant</p></header>
<div class="vin-message__content"><p>Small diff, big thoughts.<br>A nit becomes a thread:<br>approved, with comments.</p></div>
</div>
</article>
<article class="vin-message vin-message--end">
<div class="vin-message__body">
<div class="vin-message__content"><p class="vin-bubble vin-bubble--user">Now one about deploying on a Friday.</p></div>
</div>
</article>
<article class="vin-message">
<div class="vin-message__avatar" aria-hidden="true">
<span class="vin-avatar vin-avatar--sm vin-avatar--square" role="img" aria-label="Assistant"><span class="vin-avatar__fallback">AI</span></span>
</div>
<div class="vin-message__body">
<header class="vin-message__header"><p class="vin-message__author">Assistant</p></header>
<div class="vin-message__content"><p>Green checks at five.<br>The weekend hums, then a page:<br>rollback by moonlight.</p></div>
</div>
</article>
<article class="vin-message vin-message--end">
<div class="vin-message__body">
<div class="vin-message__content"><p class="vin-bubble vin-bubble--user">Ha. One more, about naming things?</p></div>
</div>
</article>
<article class="vin-message">
<div class="vin-message__avatar" aria-hidden="true">
<span class="vin-avatar vin-avatar--sm vin-avatar--square" role="img" aria-label="Assistant"><span class="vin-avatar__fallback">AI</span></span>
</div>
<div class="vin-message__body">
<div class="vin-message__content">
<div class="vin-bubble vin-bubble--typing" role="status">
<span class="vin-bubble__dot"></span>
<span class="vin-bubble__dot"></span>
<span class="vin-bubble__dot"></span>
<span class="vin-bubble__label">Assistant is typing</span>
</div>
</div>
</div>
</article>
</div>
</div>
<button type="button" class="vin-btn vin-btn--secondary vin-btn--sm vin-message-scroller__jump" hidden><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 5v14"/><path d="m19 12-7 7-7-7"/></svg>Jump to latest</button>
</div>import { MessageScroller } from "@/components/vin/message-scroller";
import { Message } from "@/components/vin/message";
import { Bubble, TypingBubble } from "@/components/vin/bubble";
import { Avatar } from "@/components/vin/avatar";
const assistant = <Avatar name="Assistant" size="sm" shape="square" fallback="AI" />;
export function MessageScrollerMessages() {
return (
<MessageScroller outline label="Chat with the assistant" style={{ width: "100%", maxWidth: 560, height: 360 }}>
<Message align="end"><Bubble as="p" from="user">Write a haiku about code review.</Bubble></Message>
<Message avatar={assistant} author="Assistant">
<p>Small diff, big thoughts.<br />A nit becomes a thread:<br />approved, with comments.</p>
</Message>
<Message align="end"><Bubble as="p" from="user">Now one about deploying on a Friday.</Bubble></Message>
<Message avatar={assistant} author="Assistant">
<p>Green checks at five.<br />The weekend hums, then a page:<br />rollback by moonlight.</p>
</Message>
<Message align="end"><Bubble as="p" from="user">Ha. One more, about naming things?</Bubble></Message>
<Message avatar={assistant}><TypingBubble /></Message>
</MessageScroller>
);
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import MessageScroller from "@/components/vin/message-scroller.vue";
import Message from "@/components/vin/message.vue";
import Avatar from "@/components/vin/avatar.vue";
import Bubble, { TypingBubble } from "@/components/vin/bubble.vue";
</script>
<template>
<MessageScroller outline label="Chat with the assistant" style="width: 100%; max-width: 560px; height: 360px">
<Message align="end"><Bubble as="p" from="user">Write a haiku about code review.</Bubble></Message>
<Message author="Assistant">
<template #avatar><Avatar name="Assistant" size="sm" shape="square" fallback="AI" /></template>
<p>Small diff, big thoughts.<br />A nit becomes a thread:<br />approved, with comments.</p>
</Message>
<Message align="end"><Bubble as="p" from="user">Now one about deploying on a Friday.</Bubble></Message>
<Message author="Assistant">
<template #avatar><Avatar name="Assistant" size="sm" shape="square" fallback="AI" /></template>
<p>Green checks at five.<br />The weekend hums, then a page:<br />rollback by moonlight.</p>
</Message>
<Message align="end"><Bubble as="p" from="user">Ha. One more, about naming things?</Bubble></Message>
<Message>
<template #avatar><Avatar name="Assistant" size="sm" shape="square" fallback="AI" /></template>
<TypingBubble />
</Message>
</MessageScroller>
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import MessageScroller from "$lib/components/vin/message-scroller.svelte";
import Message from "$lib/components/vin/message.svelte";
import Bubble from "$lib/components/vin/bubble.svelte";
import TypingBubble from "$lib/components/vin/bubble-typing.svelte";
import Avatar from "$lib/components/vin/avatar.svelte";
</script>
{#snippet assistant()}<Avatar name="Assistant" size="sm" shape="square" fallback="AI" />{/snippet}
<MessageScroller outline label="Chat with the assistant" style="width: 100%; max-width: 560px; height: 360px">
<Message align="end"><Bubble as="p" from="user">Write a haiku about code review.</Bubble></Message>
<Message avatar={assistant} author="Assistant">
<p>Small diff, big thoughts.<br />A nit becomes a thread:<br />approved, with comments.</p>
</Message>
<Message align="end"><Bubble as="p" from="user">Now one about deploying on a Friday.</Bubble></Message>
<Message avatar={assistant} author="Assistant">
<p>Green checks at five.<br />The weekend hums, then a page:<br />rollback by moonlight.</p>
</Message>
<Message align="end"><Bubble as="p" from="user">Ha. One more, about naming things?</Bubble></Message>
<Message avatar={assistant}><TypingBubble /></Message>
</MessageScroller>Installation
React, Vue and Svelte: add the component to your project with the CLI. It reads your framework from vin.json and also copies any component this one needs. Then import it:
npx @vinish/ui add message-scrollerimport { MessageScroller } from "@/components/vin/message-scroller";import MessageScroller from "@/components/vin/message-scroller.vue";import MessageScroller from "$lib/components/vin/message-scroller.svelte";The import paths assume the default folders: @/components/vin (React and Vue, with the usual @ → src alias) and $lib/components/vin (SvelteKit). Use your own if you chose another folder in init. How the Vue and Svelte versions pass values and content is in Frameworks.
Plain HTML: the classes come with the style's stylesheet. This component also needs vinui.js for its keyboard and pointer behaviour.
API
From spec/message-scroller.json, which every framework version is tested against.
| Prop | Values | Default | In HTML |
|---|---|---|---|
childrenThe messages, oldest first. | ReactNode | — | .vin-message-scroller__viewport[role=log] > .vin-message-scroller__content > … |
labelName for the log. | string | Conversation | aria-label on the viewport |
outlineDraw a frame: surface, border and rounded corners. | boolean | false | vin-message-scroller--outline |
jumpLabel | string | Jump to latest | button.vin-btn.vin-btn--secondary.vin-btn--sm.vin-message-scroller__jump[hidden] |
thresholdHow close to the bottom, in pixels, still counts as "at the bottom". | number | 32 | — |
viewportPropsProps for the scrolling element. | HTMLAttributes | — | — |
heightGive the scroller a height (or put it in a flex column); the viewport scrolls inside it. | CSS | — | style="height: …" on .vin-message-scroller |
Parts
| React, Vue, Svelte | HTML classes |
|---|---|
<MessageScroller> | .vin-message-scroller.vin-message-scroller--outline.vin-message-scroller__viewport.vin-message-scroller__content.vin-message-scroller__jump |
Accessibility
- The scrolling area is a log (role="log", aria-live="polite"): screen readers announce new messages as they arrive, without moving focus.
- It is focusable (tabindex="0") and labelled, so keyboard users can scroll it with the arrow keys and Page Up / Page Down.
- It never pulls you down while you're reading older messages; the jump button is a real button and moves focus back to the log.
- With reduced motion the jump is instant instead of a smooth scroll. Set aria-busy="true" on a message while it streams so it is read once, when finished.
Customize
Saved in this browser. Style and accent are in the header.