Skip to content

XDSChatMessageList: add an align/anchor prop for top-aligned message lists #2572

Closed

Description

@rubyycheung

Problem

XDSChatMessageList always bottom-anchors its content. It renders an aria-hidden spacer <div> with flex: 1 as the first inner child, which pushes messages to the bottom of the container:

https://github.com/facebookexperimental/xds/blob/main/packages/core/src/Chat/XDSChatMessageList.tsx — see styles.spacer = { flex: 1, minHeight: 0 } and the spacer <div> rendered before children.

This is the right default for live chat (newest message visible). But some surfaces — e.g. a static/seeded conversation that fits within the viewport, or an artifact/document side-panel chat — read better top-anchored, with messages starting at the top of the panel.

Why it can't be solved at the call site today

There is no prop (align, anchor, justify, scrollAnchor, etc.) on XDSChatMessageList or XDSChatLayout to control this. xstyle is applied to the list's root, not the inner flex container or the spacer, so the spacer's flex: 1 can't be overridden from outside. StyleX has no descendant/child combinators, so a consumer cannot target the spacer via xstyle either.

The only current workarounds all reach into the component's internal DOM:

  • A raw <style> tag with a global selector like .xds-chat-message-list > div > [aria-hidden] { flex: 0 0 0 } (anti-pattern — pierces internals, leaks globally).
  • A ref + useEffect setting the spacer's inline style (still pierces internals).

Both are exactly the kind of escape hatch the design system discourages.

Proposed solution

Add an alignment prop to XDSChatMessageList, e.g.:

/**
 * Vertical alignment of messages within the list when content
 * doesn't fill the container.
 * - 'bottom' (default): messages anchor to the bottom (live-chat behavior).
 * - 'top': messages anchor to the top (static/seeded conversations,
 *   document/artifact side panels).
 * @default 'bottom'
 */
align?: 'top' | 'bottom';

Implementation: render (or collapse) the flex: 1 spacer based on align. When align === 'top', omit the spacer (or set it to flex: 0). Auto-scroll behavior owned by XDSChatLayout should still work for the bottom case.

Remember the SYNC: block at the top of XDSChatMessageList.tsx (update index exports, Storybook stories, and the ChatMessageList block examples).

Context

Surfaced while building the ai-chat-artifact page template (packages/cli/templates/pages/ai-chat-artifact/page.tsx). The template wanted top-anchored chat; we removed the <style> workaround and reverted to the default bottom-anchor rather than ship the anti-pattern, pending this prop.

Metadata

Metadata

Assignees

No one assigned

    Labels

    componentenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions