Skip to content

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

TypeScript

fix(DropdownMenuSubMenu, Thumbnail, ChatMessageList): silence the busy Spinner and announce the busy start once (#7950)

Cindy Zhang10b832e02cea
diff --git a/.changeset/submenu-thumbnail-chatlist-busy-announces-once.md b/.changeset/submenu-thumbnail-chatlist-busy-announces-once.md
new file mode 100644
index 0000000000..80cdffa988
--- /dev/null
+++ b/.changeset/submenu-thumbnail-chatlist-busy-announces-once.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] `DropdownMenuSubMenu` (with `hasSpinner`), an uploading `Thumbnail`, and `ChatMessageList` while it loads older messages announce their busy start ("Loading") once, politely, through the shared announcement channel. The Spinner each one shows is hidden from assistive technology (`spec:AST-086` FR4, FR6, FR8). Before, that Spinner mounted as its own `role="status"` region already named "Loading", which screen readers often skip; in `ChatMessageList` it was also a second live role inside the log. Tests that found these Spinners with `getByRole('status', {name: 'Loading'})` should query the Spinner element or the owner's busy state instead.
+
+@cixzhang
diff --git a/packages/core/src/Chat/ChatMessageList.test.tsx b/packages/core/src/Chat/ChatMessageList.test.tsx
index 39bd3b1de8..bd86b547ef 100644
--- a/packages/core/src/Chat/ChatMessageList.test.tsx
+++ b/packages/core/src/Chat/ChatMessageList.test.tsx
@@ -182,9 +182,13 @@ describe('ChatMessageList', () => {
);
});
expect(action).toHaveBeenCalledTimes(1);
- expect(screen.getByRole('status', {name: 'Loading'})).toBeTruthy();
+ // The loader Spinner inside the log is silent (spec:AST-086 FR4, FR8).
+ expect(document.querySelector('.astryx-spinner')).toHaveAttribute(
+ 'aria-hidden',
+ 'true',
+ );
await act(async () => complete());
- expect(screen.queryByRole('status', {name: 'Loading'})).toBeNull();
+ expect(document.querySelector('.astryx-spinner')).toBeNull();
unmount();
expect(disconnect).toHaveBeenCalledTimes(1);
} finally {
diff --git a/packages/core/src/Chat/ChatMessageList.tsx b/packages/core/src/Chat/ChatMessageList.tsx
index 0f1cc5cba2..c11b51c368 100644
--- a/packages/core/src/Chat/ChatMessageList.tsx
+++ b/packages/core/src/Chat/ChatMessageList.tsx
@@ -37,6 +37,8 @@ import {Spinner} from '../Spinner';
import type {BaseProps} from '../BaseProps';
import type {SpacingStep} from '../utils/types';
import {themeProps} from '../utils/themeProps';
+import {useTranslator} from '../i18n';
+import {useBusyAnnouncement} from '../hooks/useBusyAnnouncement';
export interface ChatMessageListProps extends BaseProps<HTMLDivElement> {
/** Ref forwarded to the root element */
@@ -238,6 +240,10 @@ export function ChatMessageList({
const sentinelRef = useRef<HTMLDivElement>(null);
const innerRef = useRef<HTMLDivElement>(null);
const [isLoadingTop, startTransition] = useTransition();
+ const t = useTranslator();
+ // The top loading Spinner sits inside the log and is silent; the list
+ // announces its loading through the channel (spec:AST-086 FR4, FR8).
+ useBusyAnnouncement(isLoadingTop, t('@astryx.spinner.loading'), innerRef);
// Register inner content element with the layout for height observation
useEffect(() => {
@@ -309,7 +315,7 @@ export function ChatMessageList({
{/* Loading spinner at top */}
{isLoadingTop && (
<div {...stylex.props(styles.loadingTop)}>
- <Spinner size="md" />
+ <Spinner size="md" aria-hidden="true" />
</div>
)}
diff --git a/packages/core/src/Chat/__tests__/ChatMessageList.a11y.chromium.spec.ts b/packages/core/src/Chat/__tests__/ChatMessageList.a11y.chromium.spec.ts
index 1a9ff16940..95317b150d 100644
--- a/packages/core/src/Chat/__tests__/ChatMessageList.a11y.chromium.spec.ts
+++ b/packages/core/src/Chat/__tests__/ChatMessageList.a11y.chromium.spec.ts
@@ -42,7 +42,8 @@ interface Case {
direction?: 'ltr' | 'rtl';
coarsePointer?: boolean;
requiresOverflow?: boolean;
- statusName?: string;
+ /** The top loader is shown, silent inside the log (spec:AST-086 FR4, FR8). */
+ hiddenLoader?: boolean;
}
// Expectations are authored from the public fixture and component source, not
@@ -153,7 +154,7 @@ const CASES: Case[] = [
density: 'balanced',
busy: false,
text: 'Earlier message remains readable',
- statusName: 'Loading',
+ hiddenLoader: true,
},
];
@@ -228,8 +229,10 @@ async function capture(page: Page, scenario: Case, mode: 'light' | 'dark') {
);
const logs = page.getByRole('log');
await logs.first().waitFor();
- if (scenario.statusName) {
- await page.getByRole('status', {name: scenario.statusName}).waitFor();
+ if (scenario.hiddenLoader) {
+ await page
+ .locator('[role="log"] .astryx-spinner[aria-hidden="true"]')
+ .waitFor();
}
await holdMotionStill(page);
await page.evaluate(async () => document.fonts.ready);
@@ -260,17 +263,21 @@ async function capture(page: Page, scenario: Case, mode: 'light' | 'dark') {
parentClientHeight: node.parentElement?.clientHeight ?? 0,
}
: {}),
- ...(measures.status
+ ...(measures.loader
? {
- statusName: node
- .querySelector('[role="status"]')
- ?.getAttribute('aria-label'),
+ hiddenLoader:
+ node
+ .querySelector('.astryx-spinner')
+ ?.closest('[aria-hidden="true"]') != null,
+ exposedStatus: [...node.querySelectorAll('[role="status"]')].some(
+ status => status.closest('[aria-hidden="true"]') == null,
+ ),
}
: {}),
}),
{
overflow: Boolean(scenario.requiresOverflow),
- status: Boolean(scenario.statusName),
+ loader: Boolean(scenario.hiddenLoader),
},
);
const environment = await page.evaluate(() => ({
@@ -323,8 +330,9 @@ async function capture(page: Page, scenario: Case, mode: 'light' | 'dark') {
if (scenario.text != null) {
expect(observed.text).toContain(scenario.text);
}
- if (scenario.statusName != null) {
- expect(observed.statusName).toBe(scenario.statusName);
+ if (scenario.hiddenLoader) {
+ expect(observed.hiddenLoader).toBe(true);
+ expect(observed.exposedStatus).toBe(false);
}
expect(observed.width).toBeGreaterThan(0);
expect(observed.height).toBeGreaterThan(0);
@@ -371,7 +379,7 @@ async function capture(page: Page, scenario: Case, mode: 'light' | 'dark') {
text: scenario.text,
coarsePointer: scenario.coarsePointer ?? false,
...(scenario.requiresOverflow ? {requiresOverflow: true} : {}),
- ...(scenario.statusName ? {statusName: scenario.statusName} : {}),
+ ...(scenario.hiddenLoader ? {hiddenLoader: true} : {}),
},
observed: {
build: storybookSha,
diff --git a/packages/core/src/DropdownMenu/DropdownMenuSubMenu.tsx b/packages/core/src/DropdownMenu/DropdownMenuSubMenu.tsx
index ff96fd59a7..fba3193f41 100644
--- a/packages/core/src/DropdownMenu/DropdownMenuSubMenu.tsx
+++ b/packages/core/src/DropdownMenu/DropdownMenuSubMenu.tsx
@@ -72,6 +72,7 @@ import {Item} from '../Item';
import {useLayer} from '../Layer/useLayer';
import {layerAnimations} from '../Layer/layerAnimations.stylex';
import {useListFocus} from '../hooks/useListFocus';
+import {useBusyAnnouncement} from '../hooks/useBusyAnnouncement';
import {useMenuHover} from '../hooks/useMenuHover';
import {
isMenuPressActivation,
@@ -682,6 +683,14 @@ export function DropdownMenuSubMenu(
// closed from elsewhere is cancelled instead of firing into the hidden
// menu (#6893).
const isRootMenuOpen = useDropdownMenuRootOpen();
+ // The loading Spinner on the trigger is decorative; the submenu announces
+ // its busy start instead (spec:AST-086 FR8), once its level is shown: a
+ // closed menu stays mounted but hidden, and announces nothing.
+ useBusyAnnouncement(
+ hasSpinner && isRootMenuOpen,
+ t('@astryx.spinner.loading'),
+ triggerRef,
+ );
const {triggerProps, contentProps, confirmHoverOpen} =
useMenuHover<HTMLDivElement>({
show: showLayer,
@@ -1033,7 +1042,7 @@ export function DropdownMenuSubMenu(
const endAffordance = hasSpinner ? (
<span {...stylex.props(triggerStyles.caret)}>
- <Spinner size="sm" />
+ <Spinner size="sm" aria-hidden="true" />
</span>
) : (
<span {...stylex.props(triggerStyles.caret)}>
diff --git a/packages/core/src/Thumbnail/Thumbnail.test.tsx b/packages/core/src/Thumbnail/Thumbnail.test.tsx
index 3758cc00fd..712487288a 100644
--- a/packages/core/src/Thumbnail/Thumbnail.test.tsx
+++ b/packages/core/src/Thumbnail/Thumbnail.test.tsx
@@ -38,7 +38,12 @@ describe('Thumbnail', () => {
);
const img = screen.getByRole('img');
expect(img).toHaveAttribute('src', '/local.jpg');
- expect(screen.getByRole('status')).toBeInTheDocument();
+ // The upload Spinner is decorative; the thumbnail announces its busy
+ // start instead (spec:AST-086 FR8).
+ expect(document.querySelector('.astryx-spinner')).toHaveAttribute(
+ 'aria-hidden',
+ 'true',
+ );
});
it('exposes the label as an accessible name via a valid group role', () => {
diff --git a/packages/core/src/Thumbnail/Thumbnail.tsx b/packages/core/src/Thumbnail/Thumbnail.tsx
index 8f70540342..bf537534b2 100644
--- a/packages/core/src/Thumbnail/Thumbnail.tsx
+++ b/packages/core/src/Thumbnail/Thumbnail.tsx
@@ -25,7 +25,7 @@
* - /packages/cli/assets/templates/blocks/components/Thumbnail/ (showcase blocks)
*/
-import {useState} from 'react';
+import {useRef, useState} from 'react';
import * as stylex from '@stylexjs/stylex';
import {
colorVars,
@@ -40,6 +40,7 @@ import {Skeleton} from '../Skeleton';
import {Spinner} from '../Spinner';
import {Tooltip} from '../Tooltip/Tooltip';
import {useDevWarning} from '../hooks/useDevWarning';
+import {useBusyAnnouncement} from '../hooks/useBusyAnnouncement';
import {useContainerReveal} from '../hooks/useContainerReveal';
import type {BaseProps} from '../BaseProps';
import {mergeProps} from '../utils';
@@ -352,6 +353,14 @@ export function Thumbnail({
const showSkeleton = isLoading && !hasSrc;
const showImage = hasSrc && !showSkeleton && !hasError;
const showUploadOverlay = isLoading && hasSrc;
+ const uploadOverlayRef = useRef<HTMLDivElement>(null);
+ // The upload Spinner is decorative; the thumbnail announces its busy start
+ // instead (spec:AST-086 FR8).
+ useBusyAnnouncement(
+ showUploadOverlay,
+ t('@astryx.spinner.loading'),
+ uploadOverlayRef,
+ );
const showPlaceholder = (!isLoading && !hasSrc) || hasError;
const isInteractive = onClick != null && !isDisabled && !isLoading;
const hasRemove = onRemove != null && !isDisabled;
@@ -472,8 +481,8 @@ export function Thumbnail({
)}
{showImage && <div {...stylex.props(styles.insetBorder)} />}
{showUploadOverlay && (
- <div {...stylex.props(styles.uploadOverlay)}>
- <Spinner size="sm" shade="onMedia" />
+ <div ref={uploadOverlayRef} {...stylex.props(styles.uploadOverlay)}>
+ <Spinner size="sm" shade="onMedia" aria-hidden="true" />
</div>
)}
{removeButtonEl}
diff --git a/packages/core/src/__tests__/BusyOwnerAnnouncement.test.tsx b/packages/core/src/__tests__/BusyOwnerAnnouncement.test.tsx
index d110010d06..89e592a43b 100644
--- a/packages/core/src/__tests__/BusyOwnerAnnouncement.test.tsx
+++ b/packages/core/src/__tests__/BusyOwnerAnnouncement.test.tsx
@@ -30,6 +30,13 @@ import {DateRangeInput} from '../DateRangeInput';
import {DateTimeInput} from '../DateTimeInput';
import {TimeInput} from '../TimeInput';
import {CheckboxInput} from '../CheckboxInput';
+import {Thumbnail} from '../Thumbnail';
+import {
+ DropdownMenu,
+ DropdownMenuItem,
+ DropdownMenuSubMenu,
+} from '../DropdownMenu';
+import {ChatMessageList} from '../Chat';
import {BaseTypeahead, Typeahead} from '../Typeahead';
import type {SearchableItem, SearchSource} from '../Typeahead';
import type {ISOTimeString} from '../utils';
@@ -143,6 +150,12 @@ const OWNERS: ReadonlyArray<
/>
),
],
+ [
+ 'Thumbnail (uploading)',
+ isLoading => (
+ <Thumbnail src="/local.jpg" alt="Upload" isLoading={isLoading} />
+ ),
+ ],
[
'DateRangeInput',
isLoading => (
@@ -481,3 +494,83 @@ describe.each(SHEET_OWNERS)(
});
},
);
+
+describe('DropdownMenuSubMenu loading state (spec:AST-086 FR8)', () => {
+ function Menu({isLoading}: {isLoading: boolean}) {
+ return (
+ <DropdownMenu button={{label: 'Actions'}}>
+ <DropdownMenuSubMenu label="Move to" hasSpinner={isLoading}>
+ <DropdownMenuItem label="Inbox" onClick={() => {}} />
+ </DropdownMenuSubMenu>
+ </DropdownMenu>
+ );
+ }
+
+ it('announces nothing while its menu is closed', async () => {
+ render(strict(<Menu isLoading />));
+ await nextFrame();
+ expect(busyAnnouncements()).toEqual([]);
+ });
+
+ it('announces the busy start when its menu opens while loading', async () => {
+ render(strict(<Menu isLoading />));
+ fireEvent.click(screen.getByRole('button', {name: /Actions/}));
+ await nextFrame();
+ expect(busyAnnouncements()).toEqual([['Loading', 'polite']]);
+ });
+
+ it('keeps the trigger Spinner silent and announces each busy start once', async () => {
+ const {rerender} = render(strict(<Menu isLoading={false} />));
+ fireEvent.click(screen.getByRole('button', {name: /Actions/}));
+ await nextFrame();
+ expect(busyAnnouncements()).toEqual([]);
+ rerender(strict(<Menu isLoading />));
+ await nextFrame();
+ const spinner = document.querySelector('.astryx-spinner');
+ expect(spinner).toHaveAttribute('aria-hidden', 'true');
+ expect(busyAnnouncements()).toEqual([['Loading', 'polite']]);
+ rerender(strict(<Menu isLoading={false} />));
+ rerender(strict(<Menu isLoading />));
+ await nextFrame();
+ expect(busyAnnouncements()).toEqual([
+ ['Loading', 'polite'],
+ ['Loading', 'polite'],
+ ]);
+ });
+});
+
+describe('ChatMessageList top loader (spec:AST-086 FR4, FR8)', () => {
+ it('keeps the loader inside the log silent and announces loading once through the channel', async () => {
+ let notify!: IntersectionObserverCallback;
+ vi.stubGlobal(
+ 'IntersectionObserver',
+ class {
+ constructor(callback: IntersectionObserverCallback) {
+ notify = callback;
+ }
+ observe() {}
+ disconnect() {}
+ },
+ );
+ render(
+ strict(
+ <ChatMessageList
+ scrollToTopAction={async () => new Promise<void>(() => {})}>
+ <div>Earlier message</div>
+ </ChatMessageList>,
+ ),
+ );
+ act(() => {
+ notify(
+ [{isIntersecting: true} as IntersectionObserverEntry],
+ {} as IntersectionObserver,
+ );
+ });
+ await nextFrame();
+ expect(document.querySelector('.astryx-spinner')).toHaveAttribute(
+ 'aria-hidden',
+ 'true',
+ );
+ expect(busyAnnouncements()).toEqual([['Loading', 'polite']]);
+ });
+});