An open source design system that's fully customizable and agent ready
TypeScript
fix(CheckboxInput): announce the busy start once (#7948)
Cindy Zhangc9c991e3bdd6
diff --git a/.changeset/checkbox-busy-announces-once.md b/.changeset/checkbox-busy-announces-once.mdnew file mode 100644index 0000000000..3c6547bc5a--- /dev/null+++ b/.changeset/checkbox-busy-announces-once.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[fix] `CheckboxInput` announces its busy start ("Loading") once, politely, through the shared announcement channel (`spec:AST-086` FR6, FR8). The Spinner it shows in place of the check mark while busy sits inside the decorative, hidden indicator, so before this nothing told screen-reader users that the checkbox had become busy beyond its `aria-busy`. Inside an open modal dialog the announcement goes to a status region in the dialog.++@cixzhangdiff --git a/packages/core/src/CheckboxInput/CheckboxInput.tsx b/packages/core/src/CheckboxInput/CheckboxInput.tsxindex 0e2f42c0ae..a3e9996370 100644--- a/packages/core/src/CheckboxInput/CheckboxInput.tsx+++ b/packages/core/src/CheckboxInput/CheckboxInput.tsx@@ -46,7 +46,9 @@ import {useTooltip} from '../Tooltip';import {mergeProps, rtlStyles} from '../utils';import {indicatorScope} from '../Indicator/indicator.markers.stylex';import {interactionOverlayStyles} from '../utils/interactionOverlay.stylex';+import {useTranslator} from '../i18n';import {useIndicatorFocusRing} from '../hooks/useIndicatorFocusRing';+import {useBusyAnnouncement} from '../hooks/useBusyAnnouncement';import {usePressFeedback} from '../hooks/usePressFeedback';import {useResolvedRequired} from '../hooks/useResolvedRequired';import {useIndicator} from '../Indicator';@@ -371,6 +373,10 @@ export function CheckboxInput({// `opacity: 0`, and only the indicator's own element can shape the outline// to match it. See useIndicatorFocusRing.const indicatorRef = useRef<HTMLSpanElement>(null);+ const t = useTranslator();+ // The busy Spinner sits in the decorative, aria-hidden indicator, so this+ // control announces its busy start itself (spec:AST-086 FR8).+ useBusyAnnouncement(isBusy, t('@astryx.spinner.loading'), indicatorRef);const {focusProps} = useIndicatorFocusRing(indicatorRef);const isIndeterminate = optimisticValue === 'indeterminate';diff --git a/packages/core/src/__tests__/BusyOwnerAnnouncement.test.tsx b/packages/core/src/__tests__/BusyOwnerAnnouncement.test.tsxindex d1a4a4468a..d110010d06 100644--- a/packages/core/src/__tests__/BusyOwnerAnnouncement.test.tsx+++ b/packages/core/src/__tests__/BusyOwnerAnnouncement.test.tsx@@ -29,6 +29,7 @@ import {DateInput} from '../DateInput';import {DateRangeInput} from '../DateRangeInput';import {DateTimeInput} from '../DateTimeInput';import {TimeInput} from '../TimeInput';+import {CheckboxInput} from '../CheckboxInput';import {BaseTypeahead, Typeahead} from '../Typeahead';import type {SearchableItem, SearchSource} from '../Typeahead';import type {ISOTimeString} from '../utils';@@ -131,6 +132,17 @@ const OWNERS: ReadonlyArray<),] as const,]),+ [+ 'CheckboxInput',+ isLoading => (+ <CheckboxInput+ label="Subscribe"+ value={false}+ onChange={() => {}}+ isLoading={isLoading}+ />+ ),+ ],['DateRangeInput',isLoading => (@@ -242,7 +254,8 @@ describe.each(OWNERS)('%s busy state (spec:AST-086)', (_name, renderOwner) => {const {container} = render(renderOwner(true));const spinner = container.querySelector('.astryx-spinner');expect(spinner).not.toBeNull();- expect(spinner).toHaveAttribute('aria-hidden', 'true');+ // Hidden itself, or inside a decorative hidden indicator (CheckboxInput).+ expect(spinner!.closest('[aria-hidden="true"]')).not.toBeNull();expect(screen.queryByRole('status', {name: 'Loading'})).toBeNull();});