Message Scroller

A conversation that scrolls itself: it opens on the last turn, holds a new turn near the top while its reply arrives, follows the end until you scroll away, and keeps your place when older messages load above. In the look of the app's style.

Data DisplayExperimental

Usage

import { Component, ViewEncapsulation } from '@angular/core';import {  ScBubble,  ScBubbleContent,  ScFrame,  ScMessage,  ScMessageContent,  ScMessageScroller,  ScMessageScrollerButton,  ScMessageScrollerContent,  ScMessageScrollerItem,  ScMessageScrollerViewport,} from '@semantic-components/ui';import { SiArrowDownIcon } from '@semantic-icons/lucide-icons';
@Component({  selector: 'app-message-scroller-usage-demo',  imports: [    ScFrame,    ScBubble,    ScBubbleContent,    ScMessage,    ScMessageContent,    ScMessageScroller,    ScMessageScrollerButton,    ScMessageScrollerContent,    ScMessageScrollerItem,    ScMessageScrollerViewport,    SiArrowDownIcon,  ],  template: `    <div scFrame class="h-80 overflow-hidden">      <div scMessageScroller>        <div scMessageScrollerViewport aria-label="Conversation">          <div scMessageScrollerContent class="p-4">            @for (message of messages; track message.id) {              <div                scMessageScrollerItem                [messageId]="message.id"                [scrollAnchor]="message.role === 'user'"              >                <div                  scMessage                  [alignment]="message.role === 'user' ? 'end' : 'start'"                >                  <div scMessageContent>                    <div                      scBubble                      [alignment]="message.role === 'user' ? 'end' : 'start'"                      [variant]="message.role === 'user' ? 'default' : 'muted'"                    >                      <div scBubbleContent>{{ message.text }}</div>                    </div>                  </div>                </div>              </div>            }          </div>        </div>        <button scMessageScrollerButton>          <svg siArrowDownIcon></svg>          <span class="sr-only">Scroll to the latest message</span>        </button>      </div>    </div>  `,  host: { class: 'mx-auto block w-full max-w-md' },  encapsulation: ViewEncapsulation.None,})export class MessageScrollerUsageDemo {  private readonly messages = [    { id: 'q1', role: 'user', text: 'What does a message scroller do?' },    {      id: 'a1',      role: 'assistant',      text: 'It keeps a conversation where you want it: at the end when it opens, on your question while the answer arrives, and on the message you are reading when older ones load.',    },    { id: 'q2', role: 'user', text: 'And when I scroll up?' },    {      id: 'a2',      role: 'assistant',      text: 'Then it stops following. New messages arrive without moving you, and a button appears to jump back to the latest one.',    },    { id: 'q3', role: 'user', text: 'Can a keyboard scroll it?' },    {      id: 'a3',      role: 'assistant',      text: 'Yes. The conversation is a region you can tab to, and the arrow keys, Page Up, Page Down, Home and End scroll it.',    },    { id: 'q4', role: 'user', text: 'Do screen readers hear new messages?' },    {      id: 'a4',      role: 'assistant',      text: 'They do: the messages are a log, so each new one is announced once it is added.',    },  ];}

Anatomy

Every part is a directive on your element; the messages and the button's icon and name are yours. Its state and commands, through exportAs: scrollable(), visibility(), scrollToEnd(), scrollToStart(), scrollToMessage(id).

import {  ScMessageScroller, ScMessageScrollerViewport, ScMessageScrollerContent,  ScMessageScrollerItem, ScMessageScrollerButton,} from '@semantic-components/ui';
<div scMessageScroller autoScroll #scroller="scMessageScroller">  <div scMessageScrollerViewport aria-label="…">    <div scMessageScrollerContent>      <div scMessageScrollerItem messageId="…" scrollAnchor>…</div>    </div>  </div>  <button scMessageScrollerButton>…</button></div>

Accessibility

  • The viewport is a region you can tab to — name it (aria-label); the arrow keys, Page Up, Page Down, Home and End scroll it.
  • The content is a log: each new message is announced once, as it is added. Keep history controls (Load earlier) outside it, or they are read as messages.
  • The scroll button is hidden and inert while there is nothing to scroll to; name it in sr-only text.

Examples

Anchoring turns

What does a message scroller do?
It keeps a conversation where you want it: at the end when it opens, on your question while the answer arrives.
And when I scroll up?
Then it stops following. New messages arrive without moving you, and a button appears to jump back.
Can a keyboard scroll it?
Yes: the conversation is a region you can tab to, and the arrow keys, Page Up, Page Down, Home and End scroll it.
import { Component, ViewEncapsulation, signal } from '@angular/core';import {  ScBubble,  ScBubbleContent,  ScButton,  ScFrame,  ScMessage,  ScMessageContent,  ScMessageScroller,  ScMessageScrollerButton,

Group chat

Olivia
The release is on Friday.
Is the changelog ready?
Olivia
Almost: two entries left.
Sam
I can write them today.
Thanks, Sam.
Olivia
Then we are on track.
import { Component, ViewEncapsulation, signal } from '@angular/core';import {  ScBubble,  ScBubbleContent,  ScButton,  ScFrame,  ScMarker,  ScMarkerContent,  ScMessage,  ScMessageContent,

Keeping context visible

What does a message scroller do?
It keeps a conversation where you want it: at the end when it opens, on your question while the answer arrives.
And when I scroll up?
Then it stops following. New messages arrive without moving you, and a button appears to jump back.
Can a keyboard scroll it?
Yes: the conversation is a region you can tab to, and the arrow keys, Page Up, Page Down, Home and End scroll it.
Peek
import { Component, ViewEncapsulation, signal } from '@angular/core';import {  ScBubble,  ScBubbleContent,  ScButton,  ScFrame,  ScMessage,  ScMessageContent,  ScMessageScroller,  ScMessageScrollerButton,

Following the live edge

What does a message scroller do?
It keeps a conversation where you want it: at the end when it opens, on your question while the answer arrives, and on the message you are reading when older ones load.
And when I scroll up?
Then it stops following. New messages arrive without moving you, and a button appears to jump back to the latest one.
Can a keyboard scroll it?
Yes. The conversation is a region you can tab to, and the arrow keys, Page Up, Page Down, Home and End scroll it.
Do screen readers hear new messages?
They do: the messages are a log, so each new one is announced once it is added.
import {  Component,  DestroyRef,  ViewEncapsulation,  inject,  signal,} from '@angular/core';import {  ScBubble,  ScBubbleContent,

Opening saved threads

What does a message scroller do?
It keeps a conversation where you want it: at the end when it opens, on your question while the answer arrives, and on the message you are reading when older ones load.
And when I scroll up?
Then it stops following. New messages arrive without moving you, and a button appears to jump back to the latest one.
Can a keyboard scroll it?
Yes. The conversation is a region you can tab to, and the arrow keys, Page Up, Page Down, Home and End scroll it.
Do screen readers hear new messages?
They do: the messages are a log, so each new one is announced once it is added.
Where does it open?
Where you say: at the end, at the start, or — here — at the last question, so a long answer reads from its beginning. With "last-anchor", the last row with scrollAnchor opens near the top, the previous message peeking above it. With "last-anchor", the last row with scrollAnchor opens near the top, the previous message peeking above it. With "last-anchor", the last row with scrollAnchor opens near the top, the previous message peeking above it. With "last-anchor", the last row with scrollAnchor opens near the top, the previous message peeking above it. With "last-anchor", the last row with scrollAnchor opens near the top, the previous message peeking above it. With "last-anchor", the last row with scrollAnchor opens near the top, the previous message peeking above it. With "last-anchor", the last row with scrollAnchor opens near the top, the previous message peeking above it. With "last-anchor", the last row with scrollAnchor opens near the top, the previous message peeking above it.
import { Component, ViewEncapsulation } from '@angular/core';import {  ScBubble,  ScBubbleContent,  ScFrame,  ScMessage,  ScMessageContent,  ScMessageScroller,  ScMessageScrollerButton,  ScMessageScrollerContent,

Loading earlier messages

Can a keyboard scroll it?
Yes. The conversation is a region you can tab to, and the arrow keys, Page Up, Page Down, Home and End scroll it.
Do screen readers hear new messages?
They do: the messages are a log, so each new one is announced once it is added.
import { Component, ViewEncapsulation, signal } from '@angular/core';import {  ScBubble,  ScBubbleContent,  ScButton,  ScFrame,  ScMessage,  ScMessageContent,  ScMessageScroller,  ScMessageScrollerButton,

Animating new messages

What does a message scroller do?
It keeps a conversation where you want it: at the end when it opens, on your question while the answer arrives.
And when I scroll up?
Then it stops following. New messages arrive without moving you, and a button appears to jump back.
Can a keyboard scroll it?
Yes: the conversation is a region you can tab to, and the arrow keys, Page Up, Page Down, Home and End scroll it.
import { Component, ViewEncapsulation, signal } from '@angular/core';import {  ScBubble,  ScBubbleContent,  ScButton,  ScFrame,  ScMessage,  ScMessageContent,  ScMessageScroller,  ScMessageScrollerButton,

Jumping to messages

What does a message scroller do?
It keeps a conversation where you want it: at the end when it opens, on your question while the answer arrives, and on the message you are reading when older ones load.
And when I scroll up?
Then it stops following. New messages arrive without moving you, and a button appears to jump back to the latest one.
Can a keyboard scroll it?
Yes. The conversation is a region you can tab to, and the arrow keys, Page Up, Page Down, Home and End scroll it.
Do screen readers hear new messages?
They do: the messages are a log, so each new one is announced once it is added.

Reading: —

import {  Component,  ViewEncapsulation,  computed,  viewChild,} from '@angular/core';import {  ScBubble,  ScBubbleContent,  ScButton,

Tracking the reader’s position

What does a message scroller do?
It keeps a conversation where you want it: at the end when it opens, on your question while the answer arrives.
And when I scroll up?
Then it stops following. New messages arrive without moving you, and a button appears to jump back.
Can a keyboard scroll it?
Yes: the conversation is a region you can tab to, and the arrow keys, Page Up, Page Down, Home and End scroll it.
import { Component, ViewEncapsulation, computed, signal } from '@angular/core';import {  ScBubble,  ScBubbleContent,  ScButton,  ScFrame,  ScMessage,  ScMessageContent,  ScMessageScroller,  ScMessageScrollerButton,

Reading scroll state

What does a message scroller do?
It keeps a conversation where you want it: at the end when it opens, on your question while the answer arrives.
And when I scroll up?
Then it stops following. New messages arrive without moving you, and a button appears to jump back.
Can a keyboard scroll it?
Yes: the conversation is a region you can tab to, and the arrow keys, Page Up, Page Down, Home and End scroll it.

At the start · At the end

import { Component, ViewEncapsulation, signal } from '@angular/core';import {  ScBubble,  ScBubbleContent,  ScFrame,  ScMessage,  ScMessageContent,  ScMessageScroller,  ScMessageScrollerButton,  ScMessageScrollerContent,

RTL

ماذا يفعل مُمرِّر الرسائل؟
يُبقي المحادثة حيث تريد: في نهايتها عند الفتح، وعلى سؤالك أثناء وصول الجواب، وعلى الرسالة التي تقرؤها عند تحميل الرسائل الأقدم.
وإذا مرّرت إلى الأعلى؟
يتوقّف عن المتابعة. تصل الرسائل الجديدة دون أن تُحرّكك، ويظهر زرّ للعودة إلى آخر رسالة.
هل يمكن التمرير بلوحة المفاتيح؟
نعم: المحادثة منطقة تصل إليها بمفتاح Tab، وتمرّرها الأسهم و Page Up و Page Down و Home و End.
وهل تسمع قارئات الشاشة الرسائل الجديدة؟
نعم: الرسائل سجلّ، فتُعلَن كلّ رسالة جديدة عند إضافتها.
import { Dir } from '@angular/cdk/bidi';import { Component, LOCALE_ID, ViewEncapsulation } from '@angular/core';import {  ScBubble,  ScBubbleContent,  ScFrame,  ScMessage,  ScMessageContent,  ScMessageScroller,  ScMessageScrollerButton,

API reference

Each part takes class, merged over the style (cn: a later class wins).

PartSelectorDescription
ScMessageScrollerdiv[scMessageScroller] autoScroll, defaultScrollPosition ('end', 'last-anchor', 'start'), scrollPreviousItemPeek (64), scrollEdgeThreshold, scrollMargin. exportAs: scrollable(), visibility(), scrollToEnd(), scrollToStart(), scrollToMessage(id).
ScMessageScrollerViewportdiv[scMessageScrollerViewport] The scrolling region (name it); hidden until its opening position is applied.
ScMessageScrollerContentdiv[scMessageScrollerContent] The rows, a log: each new one announced.
ScMessageScrollerItemdiv[scMessageScrollerItem] A row: messageId (to jump to it), scrollAnchor (a new turn starts here).
ScMessageScrollerButtonbutton[scMessageScrollerButton] To the end (direction 'end') or the start; the style's button, shown when there is somewhere to go.