← All proposals

Chat Panel

A layout shell for the content of an AI chat drawer or docked side panel.

Net-new componentOpen in Storybook

proposals/ChatPanel/ChatPanel.mdx48 lines · View on GitHub
import { Canvas, Controls, Meta, Title } from '@storybook/addon-docs/blocks';

import * as ChatPanelStories from './ChatPanel.stories';

<Meta of={ChatPanelStories} name='Usage' />

<Title />

## Purpose

The frame of an AI chat drawer or docked panel. It owns the layout and the scroll; the team decides what goes in each region.

## Usage

Place it inside a drawer or dock it beside the page. It fills its container, so the screen sets the height. The width comes from `size`.

- `title` sits in the title row beside the built-in close button. `closeButtonLabel` is the screen-reader text and tooltip; pass it (translated) while `hasCloseButton` is on. It is optional: without it the package `CloseButton` uses its own `'Close'` label and a warning is logged in development.
- `header` is pinned under the title row (summary strip, context rows, tabs). `children` is the content and the only part that scrolls. `footer` is pinned at the bottom and typically holds the composer.
- `size` is `m` (25rem, the default) or `l` (37.5rem), the PDS Drawer widths.
- Pass `onFilesDrop` to let people drop files anywhere on the panel. While files are dragged over it, the content area shows an overlay with `dropLabel`, and the files go to your handler on drop. Give the same handler to Composer, whose own field still takes drops on it. Dragged text and links are ignored, and the add menu in Composer stays the keyboard route.
- `hasScrollToLatest` shows a floating button at the bottom center of the content area while it is scrolled away from the end, and keeps the view at the end as the content grows, but only while the person is already at the end (scroll up and it stops following). Pass `scrollToLatestLabel` with it: the screen-reader text and tooltip. It is optional, but without it the button has no accessible name and a warning is logged in development. The button is a bordered icon button with a raised shadow; choosing it scrolls to the end (instantly if the person prefers reduced motion) and moves focus into the stream.
- `hasContentFade` fades the bottom edge of the content area into the footer. The last line stays clear when scrolled to the end.
- Every region is optional.
- `headerInset`, `contentInset` and `footerInset` set `none` to bleed a region to the edges. Block padding stays; the child supplies its own inline padding.
- `hasHeaderDivider` and `hasFooterDivider` draw a rule under the header and above the footer.
- A view switch such as Compose / Chat / Review is the PDS `SegmentedButton` in `header`. Swap `children` when it changes; the panel does not know about it.
- Without `hasScrollToLatest` the panel does not scroll to the newest message; the screen does.

## Accessibility

- The panel is a plain `div` with no role. Pass a `role` or `aria-label` through `...props` if the screen needs a landmark (for example `role='complementary'`).
- The close button is the package `CloseButton`, a real button with a tooltip. `closeButtonLabel` is its label; without it the button falls back to the package's English `'Close'`, so pass a translated label.
- With `hasScrollToLatest`, the scroll area gets `tabindex='-1'` (focusable by script, not in the tab order). The button is a real button reachable by Tab, and Enter and Space work. Pass `scrollToLatestLabel`: it is the button's accessible name and tooltip. Choosing it scrolls to the end (instantly if the person prefers reduced motion) and moves focus into the scroll area, because the button then disappears. Nothing is announced when the button appears.
- With `onFilesDrop`, the overlay is hidden from assistive technology and a visually hidden status region (`role='status'`, polite) reads `dropLabel` when files are dragged over the panel. Dropping is mouse only: keep a keyboard way to add files (the add menu in Composer). Composer announces its own `dropLabel` the same way, so use the same wording for both or leave one out.
- Without `hasScrollToLatest` the scroll area is not focusable. Keyboard users reach it through focusable content inside; check this with long non-interactive content.
- Not checked: the a11y panel has not been run for light or dark.

## Implementation

See the table below for the available props. The other stories show bleed, a content-only panel and a long scrolling conversation. For the panel in a working chat (the empty state, a conversation with a chain of thought and a suggestion card, file drops), see the recipe `Recipes/Chat with an agent`. Change `size` in the controls. The grey `SlotPlaceholder` boxes in the stories are story-only scaffolding, not part of the component.

- `onClose` — Called when the close button is clicked.

<hr />

<Canvas of={ChatPanelStories.Default} />
<Controls of={ChatPanelStories.Default} />