Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

feat(ChatComposerDrawer): add collapsed summary composition (#5399)

athz99021b7cabf0
diff --git a/.changeset/chat-composer-drawer-badge-placement-8cq6.md b/.changeset/chat-composer-drawer-badge-placement-8cq6.md
new file mode 100644
index 0000000000..d840928b27
--- /dev/null
+++ b/.changeset/chat-composer-drawer-badge-placement-8cq6.md
@@ -0,0 +1,6 @@
+---
+'@astryxdesign/core': patch
+---
+
+[feat] ChatComposerDrawer: add a `collapsedSummary` composition slot that replaces the complete Collapsed summary anatomy part when provided. Omitting it preserves the existing neutral Badge and label.
+@aldentan
diff --git a/apps/storybook/stories/ChatComposerDrawer.stories.tsx b/apps/storybook/stories/ChatComposerDrawer.stories.tsx
index 962bedb718..d533dd2748 100644
--- a/apps/storybook/stories/ChatComposerDrawer.stories.tsx
+++ b/apps/storybook/stories/ChatComposerDrawer.stories.tsx
@@ -82,6 +82,17 @@ export const Collapsed: Story = {
},
};
+export const CustomCollapsedSummary: Story = {
+ tags: ['visual-baseline'],
+ args: {
+ count: 2,
+ label: 'Attachments',
+ collapsedSummary: <span>2 files ready</span>,
+ defaultIsCollapsed: true,
+ children: attachments,
+ },
+};
+
export const KeyboardFocus: Story = {
args: {
count: 2,
diff --git a/packages/core/src/Chat/ChatComposerDrawer.doc.mjs b/packages/core/src/Chat/ChatComposerDrawer.doc.mjs
index b016d097c9..2e15a3770a 100644
--- a/packages/core/src/Chat/ChatComposerDrawer.doc.mjs
+++ b/packages/core/src/Chat/ChatComposerDrawer.doc.mjs
@@ -7,7 +7,7 @@ export const docs = {
subComponentOf: 'Chat',
displayName: 'Chat Composer Drawer',
isHiddenFromOverview: true,
- description: "Collapsible drawer panel that sits above the chat input inside ChatComposer. Pass it to the composer's `drawer` slot to show attachments, context chips, or any supplementary content. When `count` is provided the drawer gains a collapse toggle: collapsed state shows a count summary and expanded state shows all children.",
+ description: "Collapsible drawer panel that sits above the chat input inside ChatComposer. Pass it to the composer's `drawer` slot to show attachments, context chips, or any supplementary content. When `count` is provided the drawer gains a collapse toggle: collapsed state shows the default Badge and label or caller-provided `collapsedSummary`, while expanded state shows all children.",
usage: {
description:
'Use ChatComposerDrawer in the ChatComposer drawer slot for supplementary content such as attachments, context chips, or previews. Provide count only when people should be able to collapse that content.',
@@ -42,7 +42,7 @@ export const docs = {
{
name: 'Collapsed summary',
required: false,
- description: 'The count and label presented while the drawer is collapsed.',
+ description: 'The default count Badge and label, or caller-provided visual content, presented while the drawer is collapsed.',
},
{
name: 'Content area',
@@ -86,9 +86,14 @@ export const docs = {
{
name: 'label',
type: 'string',
- description: 'Label shown next to the count in collapsed state.',
+ description: 'Label shown next to the count in the default collapsed summary and used to name the expand/collapse action.',
default: "'Items'",
},
+ {
+ name: 'collapsedSummary',
+ type: 'ReactNode',
+ description: 'Visual content for the complete Collapsed summary anatomy part. When count enables collapse, this replaces the default neutral Badge and label while the component retains disclosure behavior and accessible naming.',
+ },
{
name: 'isCollapsed',
type: 'boolean',
@@ -116,7 +121,8 @@ export const docsZh = {
propDescriptions: {
children: '抽屉内渲染的内容——标记、标签、预览或任何 React 元素。',
count: '折叠徽章中显示的总数。提供时,抽屉获得折叠/展开切换。',
- label: '折叠状态下显示在数量旁边的标签。',
+ label: '默认折叠摘要中显示在数量旁边的标签,并用于命名展开/折叠操作。',
+ collapsedSummary: '折叠摘要解剖部分的自定义视觉内容。提供 count 时替换默认的徽章和标签;组件仍负责折叠行为与无障碍命名,该内容仅用于展示。',
isCollapsed: '受控折叠状态。与 onCollapsedChange 一起使用。',
defaultIsCollapsed: '非受控模式的初始折叠状态。',
onCollapsedChange: '用户切换抽屉时触发的回调。',
@@ -131,7 +137,8 @@ export const docsDense = {
propDescriptions: {
children: 'drawer content: tokens, chips, previews, any React elements',
count: 'total count for collapsed summary; enables collapse/expand toggle',
- label: 'collapsed label next to count badge',
+ label: 'collapsed label next to the default count badge; names the disclosure action',
+ collapsedSummary: 'custom visual content replacing the complete Collapsed summary anatomy; requires count; presentation-only; default keeps Badge + label',
isCollapsed: 'controlled collapsed state',
defaultIsCollapsed: 'initial collapsed state (uncontrolled)',
onCollapsedChange: 'callback on collapse toggle',
diff --git a/packages/core/src/Chat/ChatComposerDrawer.test.tsx b/packages/core/src/Chat/ChatComposerDrawer.test.tsx
index 488c8b0b35..f624ae8266 100644
--- a/packages/core/src/Chat/ChatComposerDrawer.test.tsx
+++ b/packages/core/src/Chat/ChatComposerDrawer.test.tsx
@@ -81,4 +81,50 @@ describe('ChatComposerDrawer', () => {
fireEvent.keyDown(toggle, {key: ' '});
expect(onCollapsedChange).toHaveBeenLastCalledWith(false);
});
+
+ it('preserves the Badge and label as the default collapsed summary', () => {
+ const {container} = render(
+ <ChatComposerDrawer count={3} label="Attachments" defaultIsCollapsed>
+ <span>Drawer content</span>
+ </ChatComposerDrawer>,
+ );
+
+ expect(container.querySelector('.astryx-badge')).toHaveTextContent('3');
+ expect(screen.getByText('Attachments')).toBeInTheDocument();
+ });
+
+ it('replaces the complete collapsed summary with caller content', () => {
+ const {container} = render(
+ <ChatComposerDrawer
+ count={3}
+ label="Attachments"
+ collapsedSummary={<button type="button">Files ready</button>}
+ defaultIsCollapsed>
+ <span>Drawer content</span>
+ </ChatComposerDrawer>,
+ );
+
+ const toggle = screen.getByRole('button', {name: /Attachments/});
+ const customSummary = screen.getByText('Files ready');
+ const summaryBoundary = customSummary.closest('[inert]');
+ expect(toggle).not.toHaveAccessibleName(/Files ready/);
+ expect(summaryBoundary).toHaveAttribute('aria-hidden', 'true');
+ expect(container.querySelector('.astryx-badge')).toBeNull();
+ expect(screen.queryByText('Attachments')).toBeNull();
+ expect(
+ screen.queryByRole('button', {name: 'Files ready'}),
+ ).not.toBeInTheDocument();
+ });
+
+ it('does not expose collapsedSummary when count is omitted', () => {
+ render(
+ <ChatComposerDrawer collapsedSummary={<span>Files ready</span>}>
+ <span>Drawer content</span>
+ </ChatComposerDrawer>,
+ );
+
+ expect(screen.queryByText('Files ready')).not.toBeInTheDocument();
+ expect(screen.queryByRole('button')).not.toBeInTheDocument();
+ expect(screen.getByText('Drawer content')).toBeInTheDocument();
+ });
});
diff --git a/packages/core/src/Chat/ChatComposerDrawer.tsx b/packages/core/src/Chat/ChatComposerDrawer.tsx
index fbc1cd8335..8df85ec892 100644
--- a/packages/core/src/Chat/ChatComposerDrawer.tsx
+++ b/packages/core/src/Chat/ChatComposerDrawer.tsx
@@ -7,8 +7,8 @@
* @input Uses React, StyleX, theme tokens
* @output Exports ChatComposerDrawer component
* @position Collapsible drawer panel for ChatComposer.
- * Supports expanded (full content) and collapsed (count + label) states
- * with fade animation and grid-template-rows height transition.
+ * Supports expanded (full content) and collapsed (default or caller-composed
+ * summary) states with fade animation and grid-template-rows height transition.
* The collapse toggle exposes aria-expanded + aria-controls linking it to
* the content region (disclosure pattern).
*
@@ -51,10 +51,18 @@ export interface ChatComposerDrawerProps extends BaseProps<HTMLDivElement> {
*/
count?: number;
/**
- * Label shown next to the count in collapsed state.
+ * Label shown next to the count in the default collapsed summary and used to
+ * name the expand/collapse action.
* @default 'Items'
*/
label?: string;
+ /**
+ * Visual content for the canonical Collapsed summary anatomy part. Replaces
+ * the complete default Badge and label when count enables collapse. The
+ * component keeps this content presentation-only and owns disclosure
+ * semantics and accessible naming.
+ */
+ collapsedSummary?: ReactNode;
/**
* Whether the drawer is collapsed.
* Uncontrolled by default (internal toggle).
@@ -115,8 +123,8 @@ const styles = stylex.create({
borderStartEndRadius: radiusVars['--radius-chat'],
},
- // Toggle row — both the bar handle and badge+label live in the
- // same grid cell so they crossfade without layout shift.
+ // Toggle row — both the collapsed summary and bar handle live in the same
+ // grid cell so they crossfade without layout shift.
toggleRow: {
display: 'grid',
gridTemplateColumns: '1fr',
@@ -137,6 +145,7 @@ const styles = stylex.create({
justifySelf: 'start',
display: 'inline-flex',
alignItems: 'center',
+ pointerEvents: 'none',
height: spacingVars['--spacing-5'],
gap: spacingVars['--spacing-2'],
borderRadius: radiusVars['--radius-full'],
@@ -234,6 +243,7 @@ export function ChatComposerDrawer({
children,
count,
label: labelFromProps,
+ collapsedSummary,
isCollapsed: controlledCollapsed,
defaultIsCollapsed = false,
onCollapsedChange,
@@ -303,12 +313,20 @@ export function ChatComposerDrawer({
}
}}>
<div
+ aria-hidden="true"
+ inert
{...stylex.props(
styles.toggleContent,
!isCollapsed && styles.toggleContentHidden,
)}>
- <Badge variant="neutral" label={count} />
- <span {...stylex.props(styles.collapseLabel)}>{label}</span>
+ {collapsedSummary === undefined ? (
+ <>
+ <Badge variant="neutral" label={count} />
+ <span {...stylex.props(styles.collapseLabel)}>{label}</span>
+ </>
+ ) : (
+ collapsedSummary
+ )}
</div>
<div
{...stylex.props(