Skip to content

Commit 6d105d4

Browse files
committed
fix(Spinner): announce standalone loading through the shared channel
1 parent e0afabe commit 6d105d4

44 files changed

Lines changed: 629 additions & 134 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@astryxdesign/core': patch
3+
---
4+
5+
[fix] Route standalone Spinner labels through the shared polite announcement channel once per appearance or label change, rather than mounting a status region with its name. Rerenders and StrictMode replay do not repeat the channel call; a new appearance with the same words does. Keep package-owned composed indicators silent and visible labels readable. Spinner's ring now exposes `role="img"` instead of `role="status"`; update tests that query a standalone Spinner by its old role. Default sizing, animation, and label naming are unchanged.
6+
@korkt-kim

‎apps/storybook/stories/Spinner.stories.tsx‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
// Copyright (c) Meta Platforms, Inc. and affiliates.
22

3-
import type {CSSProperties} from 'react';
3+
/**
4+
* @file Spinner.stories.tsx
5+
* @input Spinner, React state, and theme fixtures
6+
* @output Spinner examples and a repeatable conditional-announcement scenario
7+
* @position Storybook visual and assistive-technology verification surface
8+
*/
9+
10+
import {StrictMode, useState, type CSSProperties} from 'react';
411
import type {Meta, StoryObj} from '@storybook/react';
512
import {Spinner} from '@astryxdesign/core/Spinner';
13+
import {Button} from '@astryxdesign/core/Button';
614
import {Text} from '@astryxdesign/core/Text';
715
import {HStack, VStack} from '@astryxdesign/core/Layout';
816
import {Theme, defineTheme} from '@astryxdesign/core/theme';
@@ -49,6 +57,31 @@ export const Default: Story = {
4957
},
5058
};
5159

60+
export const ConditionalAppearance: Story = {
61+
render: function ConditionalAppearance() {
62+
const [isLoading, setIsLoading] = useState(false);
63+
const [renderCount, setRenderCount] = useState(0);
64+
return (
65+
<StrictMode>
66+
<VStack gap={4}>
67+
<HStack gap={2}>
68+
<Button
69+
label={isLoading ? 'Finish loading' : 'Start loading'}
70+
onClick={() => setIsLoading(value => !value)}
71+
/>
72+
<Button
73+
label="Rerender"
74+
onClick={() => setRenderCount(value => value + 1)}
75+
/>
76+
</HStack>
77+
<Text>Rerenders: {renderCount}</Text>
78+
{isLoading && <Spinner label="Loading results" />}
79+
</VStack>
80+
</StrictMode>
81+
);
82+
},
83+
};
84+
5285
export const Sizes: Story = {
5386
render: () => (
5487
<HStack gap={4} vAlign="center">

‎packages/core/src/Chat/ChatMessageList.test.tsx‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* @file ChatMessageList.test.tsx
55
* @input React Testing Library, Vitest, and the public ChatMessageList surface
6-
* @output Observable log, empty-state, alignment, and async-loading regressions
6+
* @output Observable log, empty-state, alignment, and non-live loading-indicator regressions
77
* @position Colocated component behavior tests
88
*/
99

@@ -182,9 +182,10 @@ describe('ChatMessageList', () => {
182182
);
183183
});
184184
expect(action).toHaveBeenCalledTimes(1);
185-
expect(screen.getByRole('status', {name: 'Loading'})).toBeTruthy();
186-
await act(async () => complete());
185+
expect(screen.getByRole('img', {name: 'Loading'})).toBeTruthy();
187186
expect(screen.queryByRole('status', {name: 'Loading'})).toBeNull();
187+
await act(async () => complete());
188+
expect(screen.queryByRole('img', {name: 'Loading'})).toBeNull();
188189
unmount();
189190
expect(disconnect).toHaveBeenCalledTimes(1);
190191
} finally {

‎packages/core/src/CheckboxInput/CheckboxInput.tsx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
/**
66
* @file CheckboxInput.tsx
7+
* Composes a silent Spinner; the checkbox owns busy feedback.
78
* @input Uses React, useId, ChangeEvent, FieldLabel, FieldStatus, IconType, InputStatus, useTooltip
89
* @output Exports CheckboxInput component, CheckboxInputProps
910
* @position Core implementation; consumed by index.ts, tested by CheckboxInput.test.tsx
@@ -518,7 +519,9 @@ export function CheckboxInput({
518519
}
519520
size={size}
520521
isDisabled={isDisabled}>
521-
{isBusy ? <Spinner size="sm" shade="inherit" /> : null}
522+
{isBusy ? (
523+
<Spinner size="sm" shade="inherit" aria-hidden="true" />
524+
) : null}
522525
</CheckboxControl>
523526
</span>
524527
</div>

‎packages/core/src/CommandPalette/CommandPaletteInput.test.tsx‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* @file CommandPaletteInput.test.tsx
55
* @input Uses vitest, @testing-library/react, CommandPaletteInput, Dialog
6-
* @output Unit tests for CommandPaletteInput component
6+
* @output Unit tests for CommandPaletteInput and its decorative busy-indicator placement
77
* @position Testing; validates CommandPaletteInput.tsx implementation
88
*/
99

@@ -377,7 +377,10 @@ describe('CommandPaletteInput popup context', () => {
377377
</CommandPaletteContext>,
378378
);
379379

380-
const spinner = screen.getByRole('status');
380+
const spinner = screen.getByLabelText('Loading', {
381+
selector: '.astryx-spinner',
382+
});
383+
expect(spinner).toHaveAttribute('aria-hidden', 'true');
381384
const trailingContent = screen.getByTestId('trailing-content');
382385
expect(trailingContent.parentElement?.firstElementChild).toContainElement(
383386
spinner,

‎packages/core/src/CommandPalette/CommandPaletteInput.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
'use client';
44
/**
55
* @file CommandPaletteInput.tsx
6+
* Composes a silent Spinner; the palette owns busy feedback.
67
* @input Uses React, StyleX, Icon, CommandPaletteContext, DialogContext
78
* @output Exports CommandPaletteInput component and props
89
* @position Search input for the command palette
@@ -335,7 +336,7 @@ export function CommandPaletteInput({
335336
<span {...stylex.props(styles.end)}>
336337
{ctx?.isBusy && (
337338
<span {...stylex.props(styles.icon, styles.spinner)}>
338-
<Spinner size="sm" />
339+
<Spinner size="sm" aria-hidden="true" />
339340
</span>
340341
)}
341342
{hasEndContent && endContent}

‎packages/core/src/ComplexSelector/ComplexSelector.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
/**
66
* @file ComplexSelector.tsx
7+
* Composes a silent Spinner; the selector owns busy feedback.
78
* @input Uses React, StyleX, Field, Icon slots, Layer positioning, and usePopover
89
* @output Exports a rich-selector shell with exact token-sized input, secondary, and ghost triggers, plus an imperative open/close handle
910
* @position Core implementation; consumed by index.ts
@@ -790,7 +791,7 @@ export function ComplexSelector<Value>({
790791
{...stylex.props(styles.trigger)}>
791792
<span {...stylex.props(styles.triggerText)}>{triggerContent}</span>
792793
</button>
793-
{isBusy && <Spinner size="sm" />}
794+
{isBusy && <Spinner size="sm" aria-hidden="true" />}
794795
<Icon
795796
icon="chevronDown"
796797
size="sm"

‎packages/core/src/DateInput/DateInput.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
/**
66
* @file DateInput.tsx
7+
* Composes a silent Spinner; the field owns busy feedback.
78
* @input Uses React, useId, useState, useCallback, useRef, Field, Icon, Calendar, usePopover, InputGroupContext
89
* @output Exports DateInput component, DateInputProps
910
* @position Core implementation; consumed by index.ts, tested by DateInput.test.tsx
@@ -932,7 +933,7 @@ function PointerDateField({
932933
onClick={handleClear}
933934
/>
934935
)}
935-
{isBusy && <Spinner size="sm" />}
936+
{isBusy && <Spinner size="sm" aria-hidden="true" />}
936937
{statusIcon}
937938
{popover.render(
938939
<Calendar

‎packages/core/src/DateInput/NativeDateField.test.tsx‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* @file NativeDateField.test.tsx
55
* @input Uses vitest, @testing-library/react, DateInput
6-
* @output Unit tests for the OS-picker surface (`nativePicker`)
6+
* @output Unit tests for the OS-picker surface (`nativePicker`) and its silent busy indicator
77
* @position Testing; validates NativeDateField.tsx
88
*
99
* Every test renders through `DateInput` with a pointer stubbed, so the
@@ -222,7 +222,9 @@ describe('DateInput nativePicker', () => {
222222
expect(changeAction).toHaveBeenCalledExactlyOnceWith('2026-03-21');
223223
expect(getInput()).not.toBeDisabled();
224224
expect(getInput()).toHaveAttribute('aria-busy', 'true');
225-
expect(screen.getByRole('status', {name: 'Loading'})).toBeInTheDocument();
225+
expect(
226+
screen.getByLabelText('Loading', {selector: '.astryx-spinner'}),
227+
).toBeInTheDocument();
226228
expect(screen.getByText('March 21, 2026')).toBeInTheDocument();
227229

228230
fireEvent.change(getInput(), {target: {value: '2026-03-22'}});
@@ -597,7 +599,9 @@ describe('DateInput nativePicker', () => {
597599

598600
expect(calls).toEqual(['onChange', 'changeAction']);
599601
expect(changeAction).toHaveBeenCalledExactlyOnceWith(undefined);
600-
expect(screen.getByRole('status', {name: 'Loading'})).toBeInTheDocument();
602+
expect(
603+
screen.getByLabelText('Loading', {selector: '.astryx-spinner'}),
604+
).toBeInTheDocument();
601605
await act(async () => resolveAction());
602606
});
603607

‎packages/core/src/DateInput/NativeDateField.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
/**
66
* @file NativeDateField.tsx
7+
* Composes a silent Spinner; the field owns busy feedback.
78
* @input Uses React, Field, Icon, InputClearButton, Spinner, useCalendarConstraints, hasEditableDateSegments
89
* @output Exports NativeDateField — the OS-picker touch surface
910
* @position One of DateInput's three surfaces. `DateInput` picks the pointer
@@ -687,7 +688,7 @@ export function NativeDateField({
687688
onClick={handleClear}
688689
/>
689690
)}
690-
{isBusy && <Spinner size="sm" />}
691+
{isBusy && <Spinner size="sm" aria-hidden="true" />}
691692
{statusIcon}
692693
{showsDisabledMessage &&
693694
disabledMessageTooltip.renderTooltip(disabledMessage)}

0 commit comments

Comments
 (0)