Message Scroller
A chat scroll container that anchors turns, follows streamed responses, loads history without jumping and jumps to any message.
These are the headless parts of Message Scroller, which the styled Message Scroller is built on. The provider owns the behavior: it follows new messages while the reader is at the end, keeps their place while they read earlier ones, and holds the scroll position steady when history loads above.
Anatomy
Import the primitives and assemble the parts:
@using Blazix.Primitives
<MessageScrollerProvider>
<MessageScrollerRoot>
<MessageScrollerViewport>
<MessageScrollerContent>
<MessageScrollerItem />
</MessageScrollerContent>
</MessageScrollerViewport>
<MessageScrollerButton />
</MessageScrollerRoot>
</MessageScrollerProvider>Scrolling from code
Keep a @ref to the provider for its commands:
ScrollToStartAsync, ScrollToEndAsync, and ScrollToMessageAsync for an item
with a MessageId.
<MessageScrollerProvider @ref="_scroller">
...
</MessageScrollerProvider>
<button type="button" @onclick="() => _scroller!.ScrollToMessageAsync(firstUnreadId)">First unread</button>
@code {
private MessageScrollerProvider? _scroller;
}MessageScrollerScrollable renders its content with whether there's more to scroll toward each edge,
and MessageScrollerVisibility with the messages in view and the anchored turn, again whenever they
change.
API Reference
MessageScrollerProvider
Doesn't render its own HTML element.
MessageScrollerRoot
Renders a <div> element.
Other attributes are passed to the element it renders.
MessageScrollerViewport
Renders a <div> element.
Other attributes are passed to the element it renders.
MessageScrollerContent
Renders a <div> element.
Other attributes are passed to the element it renders.
MessageScrollerItem
Renders a <div> element.
Other attributes are passed to the element it renders.
MessageScrollerButton
Renders a <button> element.
Other attributes are passed to the element it renders.
MessageScrollerScrollable
Doesn't render its own HTML element.
MessageScrollerVisibility
Doesn't render its own HTML element.