diff --git a/.changeset/spinner-audit.md b/.changeset/spinner-audit.md new file mode 100644 index 0000000000000..1c49bae3da3eb --- /dev/null +++ b/.changeset/spinner-audit.md @@ -0,0 +1,7 @@ +--- +'@astryxdesign/core': patch +--- + +[fix] Spinner: an empty or blank `aria-label` or string `label` no longer leaves the loading indicator with no accessible name. An empty or blank value counts as unset, so the indicator is named by a string label that is not empty or blank, else the translated "Loading". A standalone Spinner that shows no label text and had an empty or blank name now announces "Loading" when it appears after page load, as any other standalone Spinner does; one with label text still announces that text. To silence a Spinner inside a control that already reports that it is busy, hide it with `aria-hidden`, as the docs now say. + +@cixzhang diff --git a/apps/storybook/stories/Spinner.stories.tsx b/apps/storybook/stories/Spinner.stories.tsx index fc4ba6a338d28..3952759d6dc3f 100644 --- a/apps/storybook/stories/Spinner.stories.tsx +++ b/apps/storybook/stories/Spinner.stories.tsx @@ -65,6 +65,10 @@ export const Shades: Story = { render: () => ( + + + +
({announce: vi.fn()})); vi.mock('../hooks/useAnnounce', () => ({useAnnounce: () => announce})); @@ -189,13 +191,10 @@ describe('Spinner', () => { expect(spinner.tagName.toLowerCase()).toBe('span'); }); - // The box has always been sized by an inline width/height written after the - // caller's `style`, so the component's own size wins over a `style={{width}}` - // passed in. Making the geometry themeable changed what that value is made - // of — a composed var rather than a number — and deliberately not where it is - // written: moving the sizing into a rule would have handed a caller's inline - // width a precedence over the box it has never had. This pins the precedence - // itself, which is the part a consumer could be depending on. + // The box is sized by an inline width/height written after the caller's + // `style`, so the component's own size wins over a `style={{width}}` passed + // in. A rule instead would let a caller's inline width override the box. + // These tests pin that precedence. describe('box sizing', () => { it.each(Object.entries(SIZES))( 'falls back to the %s frame where no stylesheet has declared the var', @@ -227,12 +226,11 @@ describe('Spinner', () => { }); }); - // The themed geometry resolves in the cascade — jsdom implements no layout + // The themed geometry resolves in the cascade. jsdom implements no layout // and no custom-property registration, so no test here can reach what a - // theme actually draws; that is verified in a browser and the numbers are in - // the PR. What IS a contract a unit test can hold is the routing: a theme - // writes an override against the documented key, and it has to come out on - // the selector the component reads from. + // theme draws, and no automated check covers it. A unit test can hold the + // routing: a theme writes an override against the documented key, and it + // comes out on the selector the component reads from. describe('a theme reaches the spinner through its public vars', () => { const cssFor = ( components: Parameters[0]['components'], @@ -269,7 +267,7 @@ describe('Spinner', () => { ); }); - it('scopes a themed arc fraction to that size variant (#5819)', () => { + it('scopes a themed arc fraction to that size variant', () => { expect( cssFor({spinner: {'size:xl': {'--spinner-arc-fraction': '0.75'}}}), ).toContain( @@ -335,12 +333,9 @@ describe('Spinner ring', () => { }, ); - // The regression this file could not have caught: #5214 made the RING - // themeable and left the frame at the size's own constant, so a themed - // diameter left the svg larger than the box it sits in. The overflowing grid - // item then aligned to start rather than centre — measured in Chromium at - // 1.5 to 3.3px off across the four sizes. Nothing asserted the two agreed, - // because nothing tied them. + // A frame sized from the size constant stays larger than the box when a + // theme changes the diameter. The overflowing grid item then aligns to start + // rather than centre, 1.5 to 3.3px off across the four sizes in Chromium. it('sizes the frame from CSS, not from the size constant', () => { render(); // No viewBox, and the circles centre on the box rather than on a centre @@ -363,13 +358,13 @@ describe('Spinner ring', () => { // centre in user units — the centre is `50%`, so there is no user-unit // number to name, and the offset has to survive a themed diameter. expect(circles().arc.getAttribute('transform')).toBeNull(); + expect(declaredValue(circles().arc, 'transform')).toBe('rotate(-90deg)'); }); - // The authored dash is the size's own absolute pattern, and stays that way: - // it is what a render with no stylesheet draws, and it is byte-for-byte the - // pattern this component drew before the geometry became themeable. Scaling - // with a themed diameter is the rule's job — it composes the same two - // lengths out of the resolved diameter — and deliberately not `pathLength`'s, + // The authored dash is the size's own absolute pattern: it is what a render + // with no stylesheet draws. Scaling with a themed diameter is the rule's job + // — it composes the same two lengths out of the resolved diameter — and + // deliberately not `pathLength`'s, // which rescales against the path length the UA measures on its own // approximation of the circle and shortens the default arc by 0.64%. it.each(Object.entries(SIZES))( @@ -836,8 +831,130 @@ describe('shared announcement lifecycle', () => { ]); }); + it('announces the translated default for an empty aria-label', () => { + render(); + expect(announce).toHaveBeenCalledExactlyOnceWith('Loading', 'polite'); + }); + it('uses the accessible-name fallback for a textless ReactNode label', () => { render(