Skip to content

Commit 963ab10

Browse files
authored
Merge pull request #4627 from mastermaxx03/fix/loader-a11y-4613
frontend: Loader: Add translatable aria-label fallback
2 parents 17c7f01 + 9032ec0 commit 963ab10

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

frontend/src/components/common/Loader.test.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,28 @@ describe('Loader Component', () => {
7272
const progress = screen.getByRole('progressbar');
7373
expect(progress).toHaveClass('MuiCircularProgress-colorSecondary');
7474
});
75+
it('uses title as aria-label when provided', () => {
76+
render(
77+
<TestContext>
78+
<Loader title="Fetching data..." />
79+
</TestContext>
80+
);
7581

76-
it('renders with empty title', () => {
82+
const progress = screen.getByRole('progressbar');
83+
// Verify the explicit title is used as the accessible label
84+
expect(progress).toHaveAttribute('title', 'Fetching data...');
85+
expect(progress).toHaveAttribute('aria-label', 'Fetching data...');
86+
});
87+
it('uses translated fallback aria-label when title is empty', () => {
7788
render(
7889
<TestContext>
7990
<Loader title="" />
8091
</TestContext>
8192
);
8293

8394
const progress = screen.getByRole('progressbar');
84-
expect(progress).toHaveAttribute('title', '');
95+
expect(progress).toHaveAttribute('title', 'Loading...');
96+
expect(progress).toHaveAttribute('aria-label', 'Loading...');
8597
});
8698

8799
it('passes additional props to CircularProgress', () => {

frontend/src/components/common/Loader.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,23 @@
1717
import Box from '@mui/material/Box';
1818
import CircularProgress, { CircularProgressProps } from '@mui/material/CircularProgress';
1919
import React from 'react';
20+
import { useTranslation } from 'react-i18next';
2021

2122
export interface LoaderProps extends CircularProgressProps {
2223
noContainer?: boolean;
2324
title: string;
2425
}
2526

2627
export default function Loader(props: LoaderProps) {
28+
const { t } = useTranslation();
2729
const { noContainer = false, title, ...other } = props;
28-
const progress = <CircularProgress title={title} aria-label={title} {...other} />;
30+
const progress = (
31+
<CircularProgress
32+
title={title || t('Loading...')}
33+
aria-label={title || t('Loading...')}
34+
{...other}
35+
/>
36+
);
2937

3038
if (noContainer) return progress;
3139

frontend/src/components/common/__snapshots__/Loader.NoTitleProvided.stories.storyshot

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
class="MuiBox-root css-5cned0"
55
>
66
<span
7-
aria-label=""
7+
aria-label="Loading..."
88
class="MuiCircularProgress-root MuiCircularProgress-indeterminate MuiCircularProgress-colorPrimary css-1g0vz9s-MuiCircularProgress-root"
99
role="progressbar"
1010
style="width: 40px; height: 40px;"
11-
title=""
11+
title="Loading..."
1212
>
1313
<svg
1414
class="MuiCircularProgress-svg css-1idz92c-MuiCircularProgress-svg"

0 commit comments

Comments
 (0)