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..27387ca8aec 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,16 @@ 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('small spinner', () => { const { asFragment } = render(); expect(asFragment()).toMatchSnapshot();