Skip to content

Commit 2bb4e3f

Browse files
committed
Fix accessibility issue with ReferenceField error
1 parent d38453a commit 2bb4e3f

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

packages/ra-ui-materialui/src/field/ReferenceField.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ describe('<ReferenceField />', () => {
481481
hidden: true,
482482
});
483483
expect(ErrorIcon).not.toBeNull();
484-
expect(ErrorIcon?.getAttribute('aria-errormessage')).toBe('boo');
484+
await screen.findByText('boo');
485485
});
486486

487487
describe('link', () => {

packages/ra-ui-materialui/src/field/ReferenceField.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { LinearProgress } from '../layout';
1919
import { Link } from '../Link';
2020
import { FieldProps } from './types';
2121
import { genericMemo } from './genericMemo';
22+
import { visuallyHidden } from '@mui/utils';
2223

2324
/**
2425
* Fetch reference record, and render its representation, or delegate rendering to child component.
@@ -111,13 +112,12 @@ export const ReferenceFieldView = <
111112

112113
if (error) {
113114
return (
114-
<ErrorIcon
115-
aria-errormessage={
116-
typeof error === 'string' ? error : error?.message
117-
}
118-
color="error"
119-
fontSize="small"
120-
/>
115+
<div>
116+
<ErrorIcon role="presentation" color="error" fontSize="small" />
117+
<span style={visuallyHidden}>
118+
{typeof error === 'string' ? error : error?.message}
119+
</span>
120+
</div>
121121
);
122122
}
123123
// We explicitly check isLoading here as the record may not have an id for the reference,

0 commit comments

Comments
 (0)