An open source design system that's fully customizable and agent ready
TypeScript
fix(core): complete disclosure ARIA wiring in ChatToolCalls (#3720)
Baraa Hamodie45d9aeaf555
diff --git a/.changeset/chat-toolcalls-disclosure.md b/.changeset/chat-toolcalls-disclosure.mdnew file mode 100644index 0000000000..5f874834a9--- /dev/null+++ b/.changeset/chat-toolcalls-disclosure.md@@ -0,0 +1,6 @@+---+'@astryxdesign/core': patch+---++[fix] Chat: tool-call rows and the tool-calls group header now expose complete disclosure semantics — expandable call rows announce `aria-expanded` and reference their detail panel via `aria-controls`, and the group header references its content region. Previously an expandable call row was announced as a plain button with no indication it opens anything. (#3720)+@bhamodidiff --git a/packages/core/src/Chat/ChatToolCalls.test.tsx b/packages/core/src/Chat/ChatToolCalls.test.tsxindex 36e9664a11..232a1e8ddb 100644--- a/packages/core/src/Chat/ChatToolCalls.test.tsx+++ b/packages/core/src/Chat/ChatToolCalls.test.tsx@@ -97,4 +97,59 @@ describe('ChatToolCalls', () => {);expect(screen.getByText('git status')).toBeInTheDocument();});++ it('exposes no aria-expanded on a call row without resultDetail', () => {+ const {container} = render(+ <ChatToolCalls calls={[{name: 'bash', status: 'complete'}]} />,+ );+ expect(container.querySelector('[aria-expanded]')).toBeNull();+ });++ it('wires disclosure semantics on an expandable call row', () => {+ render(+ <ChatToolCalls+ calls={[+ {+ name: 'readFile',+ status: 'complete',+ resultDetail: <div>file contents here</div>,+ },+ ]}+ />,+ );+ const row = screen.getByRole('button');+ expect(row).toHaveAttribute('aria-expanded', 'false');+ // Detail panel is conditionally mounted, so no aria-controls while closed.+ expect(row).not.toHaveAttribute('aria-controls');+ expect(screen.queryByText('file contents here')).not.toBeInTheDocument();++ fireEvent.click(row);++ expect(row).toHaveAttribute('aria-expanded', 'true');+ const detailId = row.getAttribute('aria-controls');+ expect(detailId).toBeTruthy();+ const panel = document.getElementById(detailId as string);+ expect(panel).not.toBeNull();+ expect(panel).toHaveTextContent('file contents here');+ });++ it('points the group header aria-controls at the content region', () => {+ render(+ <ChatToolCalls+ defaultIsExpanded={true}+ calls={[+ {name: 'searchCode', status: 'complete'},+ {name: 'readFile', status: 'complete'},+ ]}+ />,+ );+ const header = screen.getByRole('button');+ expect(header).toHaveAttribute('aria-expanded', 'true');+ const regionId = header.getAttribute('aria-controls');+ expect(regionId).toBeTruthy();+ const region = document.getElementById(regionId as string);+ expect(region).not.toBeNull();+ expect(region).toHaveTextContent('searchCode');+ expect(region).toHaveTextContent('readFile');+ });});diff --git a/packages/core/src/Chat/ChatToolCalls.tsx b/packages/core/src/Chat/ChatToolCalls.tsxindex 458bcff214..9263fb1e36 100644--- a/packages/core/src/Chat/ChatToolCalls.tsx+++ b/packages/core/src/Chat/ChatToolCalls.tsx@@ -18,7 +18,7 @@* for builders to wire up.*/-import React, {useState, useCallback, type ReactNode} from 'react';+import React, {useState, useCallback, useId, type ReactNode} from 'react';import type {BaseProps} from '../BaseProps';import * as stylex from '@stylexjs/stylex';import {@@ -41,11 +41,7 @@ import {themeProps} from '../utils/themeProps';// Types// =============================================================================-export type ChatToolCallStatus =- | 'pending'- | 'running'- | 'complete'- | 'error';+export type ChatToolCallStatus = 'pending' | 'running' | 'complete' | 'error';export interface ChatToolCallItem {/** Tool/function name. */@@ -356,6 +352,7 @@ function CallRow({call}: {call: ChatToolCallItem}) {const status = call.status ?? 'complete';const hasDetail = call.resultDetail != null;const [isDetailOpen, setIsDetailOpen] = useState(false);+ const detailId = useId();const toggleDetail = hasDetail? () => setIsDetailOpen(prev => !prev)@@ -365,6 +362,8 @@ function CallRow({call}: {call: ChatToolCallItem}) {<divrole={hasDetail ? 'button' : undefined}tabIndex={hasDetail ? 0 : undefined}+ aria-expanded={hasDetail ? isDetailOpen : undefined}+ aria-controls={hasDetail && isDetailOpen ? detailId : undefined}onClick={toggleDetail}onKeyDown={hasDetail@@ -399,11 +398,7 @@ function CallRow({call}: {call: ChatToolCallItem}) {</span><span {...stylex.props(styles.callName)}>{call.name}</span>{call.node != null && (- <Badge- label={call.node}- variant="neutral"- xstyle={styles.nodePill}- />+ <Badge label={call.node} variant="neutral" xstyle={styles.nodePill} />)}{call.target != null && (<span {...stylex.props(styles.callLabel)}>{call.target}</span>@@ -448,7 +443,7 @@ function CallRow({call}: {call: ChatToolCallItem}) {<div>{row}{isDetailOpen && (- <div {...stylex.props(styles.callDetailContent)}>+ <div id={detailId} {...stylex.props(styles.callDetailContent)}>{call.resultDetail}</div>)}@@ -497,6 +492,7 @@ export function ChatToolCalls(props: ChatToolCallsProps) {const autoDefault = defaultIsExpanded ?? false;const [internalExpanded, setInternalExpanded] = useState(autoDefault);+ const contentId = useId();const isControlled = controlledExpanded !== undefined;const isExpanded = isControlled ? controlledExpanded : internalExpanded;@@ -548,6 +544,7 @@ export function ChatToolCalls(props: ChatToolCallsProps) {role="button"tabIndex={0}aria-expanded={isExpanded}+ aria-controls={contentId}onClick={toggle}onKeyDown={e => {if (e.key === 'Enter' || e.key === ' ') {@@ -613,6 +610,7 @@ export function ChatToolCalls(props: ChatToolCallsProps) {{/* Expanded: all calls with full metadata */}<div+ id={contentId}{...stylex.props(styles.groupContent,isExpanded && styles.groupContentExpanded,