Skip to content

Commit 7643e4e

Browse files
authored
fix(Notifications): improve screen-reader support (#1790)
1 parent 3e4094f commit 7643e4e

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

packages/notifications/src/elements/Notification.spec.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ describe('Notification', () => {
2020
it('has a default role attribute', () => {
2121
const { container } = render(<Notification type="success" />);
2222

23-
expect(container.firstChild).toHaveAttribute('role', 'status');
23+
expect(container.firstChild).toHaveAttribute('role', 'alert');
2424
});
2525

2626
it('can have its role attribute modified', () => {
27-
const { container } = render(<Notification type="error" role="alert" />);
27+
// eslint-disable-next-line jsx-a11y/prefer-tag-over-role
28+
const { container } = render(<Notification type="error" role="status" />);
2829

29-
expect(container.firstChild).toHaveAttribute('role', 'alert');
30+
expect(container.firstChild).toHaveAttribute('role', 'status');
3031
});
3132

3233
it('can have its role attribute removed', () => {

packages/notifications/src/elements/Notification.tsx

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,19 @@ import { validationIcons, validationHues } from '../utils/icons';
1616
* @extends HTMLAttributes<HTMLDivElement>
1717
*/
1818
export const Notification = forwardRef<HTMLDivElement, INotificationProps>(
19-
({ role, ...props }, ref) => {
20-
const Icon = props.type ? validationIcons[props.type] : InfoStrokeIcon;
21-
const hue = props.type && validationHues[props.type];
19+
({ children, type, ...props }, ref) => {
20+
const Icon = type ? validationIcons[type] : InfoStrokeIcon;
21+
const hue = type && validationHues[type];
2222

2323
return (
24-
<StyledNotification
25-
ref={ref}
26-
type={props.type}
27-
isFloating
28-
{...props}
29-
role={role === undefined ? 'status' : role}
30-
>
31-
{props.type && (
24+
<StyledNotification ref={ref} type={type} isFloating role="alert" {...props}>
25+
{type && (
3226
<StyledIcon hue={hue}>
3327
<Icon />
3428
</StyledIcon>
3529
)}
3630

37-
{props.children}
31+
{children}
3832
</StyledNotification>
3933
);
4034
}

0 commit comments

Comments
 (0)