Skip to content

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

TypeScript

fix(ChatComposer): announce the status through the shared channel, not a live region born with its text (#7894)

홍규진c1fcd07d7595
diff --git a/.changeset/chat-composer-status-announcement.md b/.changeset/chat-composer-status-announcement.md
new file mode 100644
index 0000000000..a37136d6cc
--- /dev/null
+++ b/.changeset/chat-composer-status-announcement.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] ChatComposer: a status message is announced through the shared announcement channel, errors assertively and warnings politely, once per occasion: a rerender does not repeat it, and a status that clears and then returns is announced again. Before, the status bar mounted as a `role="alert"` or `role="status"` region already holding its text, which screen readers often skip. The visible bar no longer carries a live role. No API changes.
+
+@kyu-rong
diff --git a/packages/core/src/Chat/ChatComposer.spec.md b/packages/core/src/Chat/ChatComposer.spec.md
index de374258aa..dfddd509a9 100644
--- a/packages/core/src/Chat/ChatComposer.spec.md
+++ b/packages/core/src/Chat/ChatComposer.spec.md
@@ -104,7 +104,7 @@ Consumer migration instructions belong in consumer docs and release notes.
| Primary action | send; stop | Sends the current draft or requests interruption. | Default ChatSendButton or a custom sendButton | send | `component:ChatComposer` | stable | A shown Stop action without `onStop` is currently rendered but inert. |
| Density | compact; balanced; spacious | Selects composer spacing. | Every ChatComposer | balanced | `component:ChatComposer` | stable | Unknown values are rejected by TypeScript. |
| Elevation | low; none | Selects a raised body or a flat bordered body. | Every ChatComposer | low | `component:ChatComposer` | stable | Unknown values are rejected by TypeScript. |
-| Status | absent; error; warning; top; bottom | Adds semantic feedback before or after the body. | Optional status object | absent; bottom when present | `component:ChatComposer` | stable | An omitted message currently leaves the semantic status region empty. |
+| Status | absent; error; warning; top; bottom | Adds announced feedback before or after the body. | Optional status object | absent; bottom when present | `component:ChatComposer` | stable | An omitted message renders the bar and announces nothing. |
| Named composition slots | drawer; header actions/context; input; footer/send actions | Lets callers compose supporting controls and information around the draft. | Optional, independently supplied | omitted | `component:ChatComposer` | stable | Omitted slot groups emit no empty header; footer remains for the send action. |
| BaseProps surface | ref; DOM props/events; className/style; xstyle | Extends the component with DOM identity, behavior, and styling. | Every ChatComposer | omitted | `architecture:public-component-api` | stable | These surfaces currently have split root/body ownership; see OQ2. |
@@ -113,19 +113,19 @@ Consumer migration instructions belong in consumer docs and release notes.
Draft requirements identify their basis so observed code is not mistaken for an
intentional decision. A `current` contract contains no unresolved rows.
-| ID | Candidate invariant | Basis | Draft review state |
-| ---- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------- | ------------------ |
-| FR1 | Controlled mode MUST report changes through `onChange`; uncontrolled mode MUST retain them locally. Every successful submit MUST trim and deliver the value supplied to that operation, then clear through the same value channel. | public types and docs; `architecture:public-component-api/INV3, INV9, INV12`; focused tests | settled |
-| FR2 | The default editor MUST serialize its current text/tokens, submit Enter without Shift, preserve Shift+Enter, defer during IME composition, and allow a caller key handler to prevent the default operation. | implementation, docs, and focused tests | verify |
-| FR3 | `isDisabled` MUST prevent draft edits and submissions and MUST expose `aria-disabled="true"` on the default textbox; removing the prop MUST remove that state. | `spec:AST-020/FR1` (WCAG 2.2 4.1.2); `architecture:interaction-modality/INV5`; red/green focused test | settled |
-| FR4 | When `isStopShown` is true, the default primary action MUST remain an enabled, named Stop button and call `onStop`; if editing is also disabled, ancestor styling MUST NOT block its pointer, touch, or keyboard activation. | `architecture:interaction-modality/INV4, INV7, INV9`; red/green focused and browser-story tests | settled |
-| FR5 | Omitted header slots MUST omit the header row; the drawer precedes the body; input fills the body between header and footer; footer actions precede send actions and the primary action; status follows `statusPosition`. | implementation, props, stories, and blocks | verify |
-| FR6 | Compact currently reduces body padding and gap. Balanced and spacious currently use the same body spacing. Whether spacious needs distinct output MUST remain unresolved until a component/design owner decides it. | implementation and published union; no current owner selects distinct spacious geometry | human decision |
-| FR7 | `low` currently applies low rest and medium hover/focus-within elevation; `none` applies no shadow and a border. Public theme reachability MUST cover the painting body or the public target/model MUST change through an approved compatibility path. | implementation; `architecture:component-theming-surface/INV4, INV6`; existing public issue | human decision |
-| FR8 | Keyboard focus entering the registered/default editor MUST add the shared focus indication to the body; pointer focus MUST not add that extra ring. Clicking non-interactive body space MUST focus the registered control, then a textarea fallback. | implementation; `architecture:interaction-modality/INV1–INV3, INV9`; focused tests | verify |
-| FR9 | Error status currently renders an alert; warning status renders a status; both pair a semantic icon with color and can render above or below the body. | implementation, docs, and stories; `spec:AST-020/FR1` | verify |
-| FR10 | BaseProps currently split across elements: ref, DOM props/events, `className`, and `style` reach the outer frame while `xstyle` reaches the painted body. The owning element MUST remain unresolved pending compatibility review. | implementation; `architecture:public-component-api/INV5–INV6, INV8` | human decision |
-| FR11 | The exported context MUST expose the current value, change and submit operations, placeholder, disabled/stop/send state, stop callback, and mutable input focus control to custom composition. | public export, types, docs, stories, and focused tests; `architecture:public-component-api/INV12` | verify |
+| ID | Candidate invariant | Basis | Draft review state |
+| ---- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------- | ------------------ |
+| FR1 | Controlled mode MUST report changes through `onChange`; uncontrolled mode MUST retain them locally. Every successful submit MUST trim and deliver the value supplied to that operation, then clear through the same value channel. | public types and docs; `architecture:public-component-api/INV3, INV9, INV12`; focused tests | settled |
+| FR2 | The default editor MUST serialize its current text/tokens, submit Enter without Shift, preserve Shift+Enter, defer during IME composition, and allow a caller key handler to prevent the default operation. | implementation, docs, and focused tests | verify |
+| FR3 | `isDisabled` MUST prevent draft edits and submissions and MUST expose `aria-disabled="true"` on the default textbox; removing the prop MUST remove that state. | `spec:AST-020/FR1` (WCAG 2.2 4.1.2); `architecture:interaction-modality/INV5`; red/green focused test | settled |
+| FR4 | When `isStopShown` is true, the default primary action MUST remain an enabled, named Stop button and call `onStop`; if editing is also disabled, ancestor styling MUST NOT block its pointer, touch, or keyboard activation. | `architecture:interaction-modality/INV4, INV7, INV9`; red/green focused and browser-story tests | settled |
+| FR5 | Omitted header slots MUST omit the header row; the drawer precedes the body; input fills the body between header and footer; footer actions precede send actions and the primary action; status follows `statusPosition`. | implementation, props, stories, and blocks | verify |
+| FR6 | Compact currently reduces body padding and gap. Balanced and spacious currently use the same body spacing. Whether spacious needs distinct output MUST remain unresolved until a component/design owner decides it. | implementation and published union; no current owner selects distinct spacious geometry | human decision |
+| FR7 | `low` currently applies low rest and medium hover/focus-within elevation; `none` applies no shadow and a border. Public theme reachability MUST cover the painting body or the public target/model MUST change through an approved compatibility path. | implementation; `architecture:component-theming-surface/INV4, INV6`; existing public issue | human decision |
+| FR8 | Keyboard focus entering the registered/default editor MUST add the shared focus indication to the body; pointer focus MUST not add that extra ring. Clicking non-interactive body space MUST focus the registered control, then a textarea fallback. | implementation; `architecture:interaction-modality/INV1–INV3, INV9`; focused tests | verify |
+| FR9 | Error status is announced assertively and warning status politely through the shared announcement channel, once per occasion: one state transition, which a rerender or an update to the same value does not repeat (`spec:AST-086` FR6); the status bar itself carries no live role. Both pair a semantic icon with color and can render above or below the body. | implementation, docs, and stories; `spec:AST-020/FR1`; `spec:AST-086/FR2, FR5, FR6` | verify |
+| FR10 | BaseProps currently split across elements: ref, DOM props/events, `className`, and `style` reach the outer frame while `xstyle` reaches the painted body. The owning element MUST remain unresolved pending compatibility review. | implementation; `architecture:public-component-api/INV5–INV6, INV8` | human decision |
+| FR11 | The exported context MUST expose the current value, change and submit operations, placeholder, disabled/stop/send state, stop callback, and mutable input focus control to custom composition. | public export, types, docs, stories, and focused tests; `architecture:public-component-api/INV12` | verify |
### Allowed variation
@@ -144,7 +144,7 @@ intentional decision. A `current` contract contains no unresolved rows.
| Disabled editing | Default textbox exposes disabled state and cannot edit or submit. | Supporting content remains visible. |
| Disabled, interruptible work | Stop remains named, enabled, and reachable by pointer, touch, and keyboard. | Product cancellation behavior varies. |
| Flat elevation | Body has no shadow and uses its bordered presentation; keyboard focus indication remains available. | Theme tokens vary. |
-| Status above or below | Semantic role, icon, color, and selected placement remain synchronized. | Message content and status type vary. |
+| Status above or below | Announcement urgency, icon, color, and selected placement remain synchronized. | Message content and status type vary. |
| Narrow viewport | Composer remains within its containing inline size and the primary action remains operable. | Available inline size and optional slot content vary. |
### Transformation and precedence order
@@ -165,20 +165,20 @@ intentional decision. A `current` contract contains no unresolved rows.
- **AR2 — Native actions.** The default Send and Stop controls remain native buttons with translated accessible names; disabled Send uses native disabled behavior, while explicit Stop remains operable.
- **AR3 — Keyboard editing.** Enter submission MUST preserve Shift+Enter newline behavior, IME composition, and caller cancellation through `preventDefault()`.
- **AR4 — Focus indication.** Keyboard focus in the editor MUST produce the shared visible focus treatment; pointer focus does not claim keyboard modality, and focus on an internal action remains owned by that action.
-- **AR5 — Status feedback.** Error feedback uses `role="alert"`; warning feedback uses `role="status"`; visible icon and color do not replace the caller's message content.
+- **AR5 — Status feedback.** Error feedback is announced assertively and warning feedback politely through the shared announcement channel (`spec:AST-086` FR2, FR5); the visible status bar carries no live role and stays readable. Visible icon and color do not replace the caller's message content.
## Design relationships
-| Anatomy or state | Design requirement | Representation authority | Hierarchy role | Component contract |
-| ------------------- | ------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- | -------------- | ------------------ |
-| Composer frame | Groups body and optional status into one compositional shell. | observed implementation | container | FR5 |
-| Composer body | Provides the painted rounded input/action surface and elevation. | elevation is shipped; public theme reachability is unsettled | prominent | FR7 |
-| Drawer | Places attachment/context content before the body. | delegated to `component:ChatComposerDrawer` | supporting | FR5 |
-| Header | Places caller actions at start and caller context at end. | observed implementation | supporting | FR5 |
-| Input | Owns or hosts the editing surface and its focus control. | delegated to `component:ChatComposerInput` or caller custom input | prominent | FR1–FR3, FR8, FR11 |
-| Footer | Places caller actions and the primary action on the final body row. | observed implementation | supporting | FR4–FR5 |
-| Send or stop action | Presents the current primary operation. | delegated to `component:ChatSendButton` or caller custom send button | prominent | FR1, FR4 |
-| Status message | Adds error or warning feedback before or after the body. | semantic role/color are shipped; separate public theme reachability is not asserted here | supporting | FR5, FR9, AR5 |
+| Anatomy or state | Design requirement | Representation authority | Hierarchy role | Component contract |
+| ------------------- | ------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- | -------------- | ------------------ |
+| Composer frame | Groups body and optional status into one compositional shell. | observed implementation | container | FR5 |
+| Composer body | Provides the painted rounded input/action surface and elevation. | elevation is shipped; public theme reachability is unsettled | prominent | FR7 |
+| Drawer | Places attachment/context content before the body. | delegated to `component:ChatComposerDrawer` | supporting | FR5 |
+| Header | Places caller actions at start and caller context at end. | observed implementation | supporting | FR5 |
+| Input | Owns or hosts the editing surface and its focus control. | delegated to `component:ChatComposerInput` or caller custom input | prominent | FR1–FR3, FR8, FR11 |
+| Footer | Places caller actions and the primary action on the final body row. | observed implementation | supporting | FR4–FR5 |
+| Send or stop action | Presents the current primary operation. | delegated to `component:ChatSendButton` or caller custom send button | prominent | FR1, FR4 |
+| Status message | Adds error or warning feedback before or after the body. | shared-channel announcement and color are shipped; separate public theme reachability is not asserted here | supporting | FR5, FR9, AR5 |
The aggregate Chat record currently owns the public `chat-composer` target. That
target sits on the frame and cannot select the body's non-inherited elevation and
diff --git a/packages/core/src/Chat/ChatComposer.test.tsx b/packages/core/src/Chat/ChatComposer.test.tsx
index 14f4325acd..99c03e9720 100644
--- a/packages/core/src/Chat/ChatComposer.test.tsx
+++ b/packages/core/src/Chat/ChatComposer.test.tsx
@@ -1,15 +1,23 @@
// Copyright (c) Meta Platforms, Inc. and affiliates.
import {beforeEach, describe, it, expect, vi} from 'vitest';
-import {act, render, fireEvent} from '@testing-library/react';
+import {act, render, fireEvent, screen} from '@testing-library/react';
import userEvent from '@testing-library/user-event';
-import {useEffect, useRef} from 'react';
+import {StrictMode, useEffect, useRef} from 'react';
import {ChatComposer} from './ChatComposer';
import {useChatComposerContext} from './ChatContext';
import {__resetInteractionModalityForTest} from '../utils/interactionModality';
+import type * as AnnounceModule from '../hooks/useAnnounce';
+
+const announce = vi.fn();
+vi.mock('../hooks/useAnnounce', async importOriginal => ({
+ ...(await importOriginal<typeof AnnounceModule>()),
+ useAnnounce: () => announce,
+}));
beforeEach(() => {
__resetInteractionModalityForTest();
+ announce.mockClear();
});
// The composer body — the elevated surface — is the div that wraps the input
@@ -252,3 +260,51 @@ describe('ChatComposer input composition contract', () => {
expect(document.activeElement).toBe(textarea);
});
});
+
+describe('ChatComposer status announcement (spec:AST-086)', () => {
+ const composer = (status?: {type: 'error' | 'warning'; message?: string}) => (
+ <ChatComposer onSubmit={() => {}} input={<div />} status={status} />
+ );
+
+ it('shows the status message but carries no live role (FR2)', () => {
+ render(composer({type: 'error', message: 'Send failed'}));
+ const message = screen.getByText('Send failed');
+ expect(
+ message.closest('[role="alert"], [role="status"], [aria-live]'),
+ ).toBeNull();
+ });
+
+ it('announces an error assertively and a warning politely (FR5)', () => {
+ const {rerender} = render(composer());
+ expect(announce).not.toHaveBeenCalled();
+ rerender(composer({type: 'error', message: 'Send failed'}));
+ rerender(composer({type: 'warning', message: 'Offline'}));
+ expect(announce.mock.calls).toEqual([
+ ['Send failed', 'assertive'],
+ ['Offline', 'polite'],
+ ]);
+ });
+
+ it('announces a mounted status once, even under StrictMode (FR6)', () => {
+ const status = {type: 'error' as const, message: 'Send failed'};
+ const {rerender} = render(<StrictMode>{composer(status)}</StrictMode>);
+ rerender(<StrictMode>{composer({...status})}</StrictMode>);
+ expect(announce.mock.calls).toEqual([['Send failed', 'assertive']]);
+ });
+
+ it('announces the same message again after the status clears (FR6)', () => {
+ const status = {type: 'error' as const, message: 'Send failed'};
+ const {rerender} = render(composer(status));
+ rerender(composer());
+ rerender(composer(status));
+ expect(announce.mock.calls).toEqual([
+ ['Send failed', 'assertive'],
+ ['Send failed', 'assertive'],
+ ]);
+ });
+
+ it('announces nothing for a status without a message', () => {
+ render(composer({type: 'warning'}));
+ expect(announce).not.toHaveBeenCalled();
+ });
+});
diff --git a/packages/core/src/Chat/ChatComposer.tsx b/packages/core/src/Chat/ChatComposer.tsx
index fc5122d763..8d2fb40783 100644
--- a/packages/core/src/Chat/ChatComposer.tsx
+++ b/packages/core/src/Chat/ChatComposer.tsx
@@ -26,6 +26,7 @@
import React, {
useState,
useCallback,
+ useEffect,
useRef,
useMemo,
type ReactNode,
@@ -53,6 +54,7 @@ import type {ChatComposerInputControl} from './ChatContext';
import {ChatSendButton} from './ChatSendButton';
import {themeProps} from '../utils/themeProps';
import {useTranslator} from '../i18n';
+import {useAnnounce} from '../hooks/useAnnounce';
import {focusOutlineStyles} from '../utils/focusOutline.stylex';
import {
getInteractionModality,
@@ -455,9 +457,31 @@ export function ChatComposer(props: ChatComposerProps) {
[],
);
+ // The status bar mounts together with its message, and a live region born
+ // holding its text is not reliably announced, so the message goes through
+ // the shared channel instead: errors assertively, warnings politely
+ // (spec:AST-086 FR2, FR5). The ref keeps a rerender or a StrictMode effect
+ // replay from repeating it; clearing the status re-arms it, so the same
+ // message shown again is a new occasion (FR6).
+ const announce = useAnnounce();
+ const statusType = status?.type;
+ const statusMessage = status?.message;
+ const announcedStatusRef = useRef<string | null>(null);
+ useEffect(() => {
+ if (!statusMessage) {
+ announcedStatusRef.current = null;
+ return;
+ }
+ const occasion = `${statusType}\u0000${statusMessage}`;
+ if (announcedStatusRef.current === occasion) {
+ return;
+ }
+ announcedStatusRef.current = occasion;
+ announce(statusMessage, statusType === 'error' ? 'assertive' : 'polite');
+ }, [announce, statusType, statusMessage]);
+
const statusEl = status ? (
<div
- role={status.type === 'error' ? 'alert' : 'status'}
{...stylex.props(
styles.statusBar,
statusPosition === 'top' ? styles.statusTop : styles.statusBottom,