Skip to contents

A stick-to-bottom transcript viewport for streaming chat. Follows the live edge only while the reader is at the bottom; scrolling up detaches and surfaces a jump-to-latest button. Prepended history preserves the visible anchor. Part of the chat/AI kit.

Usage

shad_message_scroller(
  id,
  ...,
  auto_scroll = TRUE,
  default_position = c("end", "start", "last-anchor"),
  jump_label = "Jump to latest",
  height = NULL,
  class = NULL
)

shad_message_scroller_item(..., anchor = FALSE, class = NULL)

Arguments

id

Element id (namespaced automatically in modules).

...

Rows – typically shad_message_scroller_item() wrapping a shad_message(), shad_bubble(), or shad_marker().

auto_scroll

If TRUE (default), follow new content while at the bottom. FALSE never auto-follows.

default_position

Initial scroll position: "end" (default), "start", or "last-anchor" (scroll the last data-anchor item to top).

jump_label

Label for the jump-to-latest button.

height

CSS height of the scroller (e.g. 400, "60vh").

class

Extra CSS classes.

anchor

If TRUE, marks this row as a turn boundary (data-anchor) for default_position = "last-anchor".

Value

A message-scroller tag.

Details

Position is not a form value, so there is no input$<id>. Drive it from the server with shad_message_scroller_to_bottom().

Examples

shad_message_scroller(
  "chat", height = 400,
  shad_message_scroller_item(shad_marker("Today", variant = "separator"),
                             anchor = TRUE),
  shad_message_scroller_item(shad_bubble("Hi!", align = "start"))
)
#> <div class="shad-message-scroller" data-shad="message-scroller" id="chat" data-auto-scroll data-default-position="end" style="height:400px;">
#>   <div class="shad-message-scroller__viewport" aria-live="polite" tabindex="0">
#>     <div class="shad-message-scroller__content">
#>       <div class="shad-message-scroller__item" data-anchor>
#>         <div class="shad-marker shad-marker--separator">
#>           <span class="shad-marker__content">Today</span>
#>         </div>
#>       </div>
#>       <div class="shad-message-scroller__item">
#>         <div class="shad-bubble shad-bubble--default shad-bubble--start">
#>           <div class="shad-bubble__content">Hi!</div>
#>         </div>
#>       </div>
#>     </div>
#>   </div>
#>   <button type="button" class="shad-message-scroller__button" aria-label="Jump to latest">
#>     <svg class="shad-icon shad-icon--sm" 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>