From bd7e869c9a96111cff6ae6e1773e4e919e8a9e02 Mon Sep 17 00:00:00 2001
From: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
Date: Fri, 8 May 2026 07:00:47 -0700
Subject: [PATCH 1/2] fix(Spinner): define default aria-label via destructuring
The Spinner default "Contents" aria-label was emitted by an inline
conditional in the JSX, so the props table for the component did not
show that there was a default value at all (#11750). Move the default
to the destructuring pattern so react-docgen surfaces it, and replace
the three conditional spread expressions with a direct attribute plus
the still-conditional aria-labelledBy spread.
Existing snapshots are unchanged (`` still renders with
aria-label="Contents"). Added unit tests cover the default value, an
explicitly provided aria-label, and aria-labelledBy.
Closes #11750
---
.../src/components/Spinner/Spinner.tsx | 5 ++---
.../Spinner/__tests__/Spinner.test.tsx | 17 ++++++++++++++++-
2 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/packages/react-core/src/components/Spinner/Spinner.tsx b/packages/react-core/src/components/Spinner/Spinner.tsx
index 77e599773c0..b0530758d1a 100644
--- a/packages/react-core/src/components/Spinner/Spinner.tsx
+++ b/packages/react-core/src/components/Spinner/Spinner.tsx
@@ -32,7 +32,7 @@ export const Spinner: React.FunctionComponent = ({
'aria-valuetext': ariaValueText = 'Loading...',
diameter,
isInline = false,
- 'aria-label': ariaLabel,
+ 'aria-label': ariaLabel = 'Contents',
'aria-labelledBy': ariaLabelledBy,
...props
}: SpinnerProps) => (
@@ -42,9 +42,8 @@ export const Spinner: React.FunctionComponent = ({
aria-valuetext={ariaValueText}
viewBox="0 0 100 100"
{...(diameter && { style: { [cssDiameter.name]: diameter } as React.CSSProperties })}
- {...(ariaLabel && { 'aria-label': ariaLabel })}
+ aria-label={ariaLabel}
{...(ariaLabelledBy && { 'aria-labelledBy': ariaLabelledBy })}
- {...(!ariaLabel && !ariaLabelledBy && { 'aria-label': 'Contents' })}
{...props}
>
diff --git a/packages/react-core/src/components/Spinner/__tests__/Spinner.test.tsx b/packages/react-core/src/components/Spinner/__tests__/Spinner.test.tsx
index 3b037f4e015..95e14db9308 100644
--- a/packages/react-core/src/components/Spinner/__tests__/Spinner.test.tsx
+++ b/packages/react-core/src/components/Spinner/__tests__/Spinner.test.tsx
@@ -1,4 +1,4 @@
-import { render } from '@testing-library/react';
+import { render, screen } from '@testing-library/react';
import { Spinner } from '../Spinner';
test('simple spinner', () => {
@@ -6,6 +6,21 @@ test('simple spinner', () => {
expect(asFragment()).toMatchSnapshot();
});
+test('uses default aria-label of "Contents" when none is provided', () => {
+ render();
+ expect(screen.getByRole('progressbar')).toHaveAttribute('aria-label', 'Contents');
+});
+
+test('uses a custom aria-label when one is provided', () => {
+ render();
+ expect(screen.getByRole('progressbar')).toHaveAttribute('aria-label', 'Loading users');
+});
+
+test('renders aria-labelledBy when provided', () => {
+ render();
+ expect(screen.getByRole('progressbar')).toHaveAttribute('aria-labelledBy', 'external-label');
+});
+
test('small spinner', () => {
const { asFragment } = render();
expect(asFragment()).toMatchSnapshot();
From ffe889da74d5d20a59e74cd527ad0a27b50d090a Mon Sep 17 00:00:00 2001
From: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
Date: Sat, 9 May 2026 09:31:24 -0700
Subject: [PATCH 2/2] test(Spinner): drop aria-labelledBy test asserting
non-spec casing
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The dropped test rendered and
asserted the SVG carried 'aria-labelledBy' (capital B). React passes
aria-* attributes to the DOM as-is, so on the SVG element this lands
as a non-standard attribute that screen readers won't find — they
look for 'aria-labelledby' (all lowercase, per WAI-ARIA spec). The
existing prop name in SpinnerProps still uses the camelCased form,
so renaming is a public API breaking change worth its own PR with
deprecation. Removing the test here keeps this PR scoped to the
default aria-label change.
---
.../src/components/Spinner/__tests__/Spinner.test.tsx | 5 -----
1 file changed, 5 deletions(-)
diff --git a/packages/react-core/src/components/Spinner/__tests__/Spinner.test.tsx b/packages/react-core/src/components/Spinner/__tests__/Spinner.test.tsx
index 95e14db9308..27387ca8aec 100644
--- a/packages/react-core/src/components/Spinner/__tests__/Spinner.test.tsx
+++ b/packages/react-core/src/components/Spinner/__tests__/Spinner.test.tsx
@@ -16,11 +16,6 @@ test('uses a custom aria-label when one is provided', () => {
expect(screen.getByRole('progressbar')).toHaveAttribute('aria-label', 'Loading users');
});
-test('renders aria-labelledBy when provided', () => {
- render();
- expect(screen.getByRole('progressbar')).toHaveAttribute('aria-labelledBy', 'external-label');
-});
-
test('small spinner', () => {
const { asFragment } = render();
expect(asFragment()).toMatchSnapshot();