Skip to content
VinUIComponentsMessage Scroller

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.

I'm going to Lisbon in March. Any tips?

March is lovely there: mild, and fewer crowds than summer. Bring good shoes, the hills are steep.

Where should I stay?

Alfama for old streets and views, Chiado for shops and cafés, or Príncipe Real if you want somewhere quieter.

How do I get from the airport?

The metro's red line goes straight to the city in about 25 minutes. A taxi takes 15 to 20 minutes.

Is a day trip to Sintra worth it?

Yes. Take the train from Rossio, go early, and book Pena Palace tickets ahead.

message-scroller-basic.html
<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>

With messages

Messages and a typing bubble at the end. New messages keep it pinned while you're at the bottom.

Write a haiku about code review.

Assistant

Small diff, big thoughts.
A nit becomes a thread:
approved, with comments.

Now one about deploying on a Friday.

Assistant

Green checks at five.
The weekend hums, then a page:
rollback by moonlight.

Ha. One more, about naming things?

Assistant is typing
message-scroller-messages.html
<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>

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:

Terminal
npx @vinish/ui add message-scroller
React
import { MessageScroller } from "@/components/vin/message-scroller";
Vue
import MessageScroller from "@/components/vin/message-scroller.vue";
Svelte
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.

PropValuesDefaultIn HTML
children
The messages, oldest first.
ReactNode—.vin-message-scroller__viewport[role=log] > .vin-message-scroller__content > …
label
Name for the log.
stringConversationaria-label on the viewport
outline
Draw a frame: surface, border and rounded corners.
booleanfalsevin-message-scroller--outline
jumpLabelstringJump to latestbutton.vin-btn.vin-btn--secondary.vin-btn--sm.vin-message-scroller__jump[hidden]
threshold
How close to the bottom, in pixels, still counts as "at the bottom".
number32—
viewportProps
Props for the scrolling element.
HTMLAttributes——
height
Give 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, SvelteHTML 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.