Create

General

Message Scroller

Copy page View as Markdown Open in ChatGPT Open in Claude

A scrolling chat thread that follows new messages, opens at the right place and keeps the reader's position.

Usage#

app.component.ts
import { WDS_MESSAGE_SCROLLER } from '@wds/angular/message-scroller';

Give the scroller or its container a height. Each row is a wds-message-scroller-item, usually holding a Message.

Examples#

Default#

The thread opens at the end. Scrolled to the end, it follows new rows; scrolled up, it stays put and wds-message-scroller-button jumps back to the end.

Which platform does the 7:40 to Kraków leave from? Platform 4, track 7. Boarding starts about ten minutes before departure. Is there a dining car? Yes, coach 5 is a dining car. It is open from departure until Katowice. Can I bring a bike? Bikes go in coach 1. Book a bike space with your ticket, there are 8 of them. What if the train is late? For a delay of 60 minutes or more you get 25% of the fare back, for 120 minutes or more 50%. How do I claim it? Fill in the delay form in the app under Trips, or at any ticket office. Keep your ticket until the claim is paid.

Open at the last question#

position="last-anchor" opens at the last row with scroll-anchor when the answer below it does not fit, so the reader starts at the question. start opens at the top.

Which platform does the 7:40 to Kraków leave from? Platform 4, track 7. Boarding starts about ten minutes before departure. Is there a dining car? Yes, coach 5 is a dining car. It is open from departure until Katowice. Can I bring a bike? Bikes go in coach 1. Book a bike space with your ticket, there are 8 of them. Explain the whole refund process for delays. Delays are counted at the station where your trip ends. A delay of 60 minutes gives 25% of the fare back, 120 minutes gives 50%. Claims are accepted for 12 months after the trip. You can send the form in the app, by e-mail or at a ticket office. The refund goes to the card used for the purchase within 30 days. For tickets bought with cash you get a bank transfer. If a connection was missed because of the delay, the whole journey counts.

Streaming reply#

A new scroll-anchor row (the question) is lifted to the top and the answer grows below it (previous-peek leaves the end of the previous row in view). busy sets aria-busy while the reply streams, so it is announced once.

Which platform does the 7:40 to Kraków leave from?Platform 4, track 7.
Ask about delays

API References#

wds-message-scroller#

Scrolling area of a conversation: wds-message-scroller-item rows in a log region. - At the end it stays at the end while rows are added or a reply streams in; scrolled up, it stays put. - position sets where a thread opens: at the end, at the start, or at the last-anchor (the last row with scroll-anchor, e.g. the last question, when the answer below does not fit). - A row with scroll-anchor added at the end (a new question) is lifted to the top, previous-peek pixels below the previous row, and the answer grows under it. - Rows added above the visible ones (loading earlier messages) do not move the view. - wds-message-scroller-button jumps to the end or start. Give the element or its container a height.

Attributes

AttributeTypeDefaultDescription
labelstring''Accessible name of the log. Empty: built-in text (messageScroller.label).
positionWdsMessageScrollerPosition'end'Where the thread opens. Applied again whenever it changes.
previous-peek.previousPeeknumber0Space in px left above a lifted scroll-anchor row for the end of the previous row.
scroll-margin.scrollMarginnumber0Space in px between the top edge and a row the scroller moves to.
busybooleanfalseA reply is still coming (aria-busy): screen readers announce the row once it is finished.

Events

EventDescription
wds-scroll-state-changeCustomEvent<WdsMessageScrollerStateDetail>Content above or below came into view or went out of it.

Methods

MethodDescription
scrollToEnd(options: { behavior?: ScrollBehavior })Scrolls to the end and keeps following new content.
scrollToStart(options: { behavior?: ScrollBehavior })Scrolls to the start.
scrollToMessage(id: string, options: { behavior?: ScrollBehavior })Scrolls the row with this message-id to the top (minus scroll-margin). Returns false when there is no such row.

Slots

SlotDescription
(default)wds-message-scroller-item rows.
buttonwds-message-scroller-button (placed there automatically).

CSS parts (::part)

PartDescription
viewportThe scrolling log region.
contentThe column with the rows.

CSS custom properties

PropertyDescription
--wds-message-scroller-gapSpace between the rows (default 24px).
--wds-message-scroller-paddingPadding around the rows (default 0).

wds-message-scroller-item#

A row of wds-message-scroller: a message, a group of messages or a divider.

Attributes

AttributeTypeDefaultDescription
scroll-anchor.scrollAnchorbooleanfalseThe row starts an exchange (e.g. the user's question): position="last-anchor" opens here and a new one is lifted to the top.
message-id.messageIdstring''Id used by scrollToMessage().

Slots

SlotDescription
(default)The row content.

wds-message-scroller-button#

Button floating over wds-message-scroller that jumps to the end (or the start). It shows only when there is content in that direction; hidden, it leaves the tab order. Place it directly in the scroller.

Attributes

AttributeTypeDefaultDescription
directionWdsMessageScrollerButtonDirection'end'Which edge the button jumps to.
variantWdsButtonVariant'outline'Button style.
sizeWdsButtonSize'sm'Button size.
labelstring''Accessible name. Empty: built-in text (messageScroller.toEnd or messageScroller.toStart).

Slots

SlotDescription
(default)Own icon or text instead of the arrow.

Accessibility#

Screen reader#

The scrolling area is a log region named by label (default Messages): screen readers announce rows added at the end. Give each thread on a page its own label.

While a reply streams set busy: the region gets aria-busy="true" and the finished row is announced once instead of after every chunk.

wds-message-scroller-button is named Scroll to end or Scroll to start (label changes it). While there is nothing to scroll to it is hidden and inert, so it leaves the tab order.

Keyboard support#

KeyFunction
TabMoves focus to the thread and to the jump button when it is shown.
ArrowUpArrowDownPageUpPageDownScrolls the focused thread.
HomeEndScrolls to the start or the end of the focused thread.
Footer