Skip to content

Commit bc19f91

Browse files
authored
fix(Notification Drawer): Added screen reader text for notification drawer item read state (#9569)
* fix(Notification Drawer): Added screen reader text for notification drawer item read state * fix snapshot * Update prop description * add aria-live * update snapshots
1 parent 7f6a62c commit bc19f91

File tree

5 files changed

+38
-3
lines changed

5 files changed

+38
-3
lines changed

packages/react-core/src/components/NotificationDrawer/NotificationDrawerHeader.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ export const NotificationDrawerHeader: React.FunctionComponent<NotificationDrawe
4242
{title}
4343
</Text>
4444
{(customText !== undefined || count !== undefined) && (
45-
<span className={css(styles.notificationDrawerHeaderStatus)}>{customText || `${count} ${unreadText}`}</span>
45+
<span className={css(styles.notificationDrawerHeaderStatus)} aria-live="polite">
46+
{customText || `${count} ${unreadText}`}
47+
</span>
4648
)}
4749
{(children || onClose) && (
4850
<div className={css(styles.notificationDrawerHeaderAction)}>

packages/react-core/src/components/NotificationDrawer/NotificationDrawerListItem.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export interface NotificationDrawerListItemProps extends React.HTMLProps<HTMLLIE
1313
isRead?: boolean;
1414
/** Callback for when a list item is clicked */
1515
onClick?: (event: any) => void;
16+
/** Visually hidden text that conveys the current read state of the notification list item */
17+
readStateScreenReaderText?: string;
1618
/** Tab index for the list item */
1719
tabIndex?: number;
1820
/** Variant indicates the severity level */
@@ -26,6 +28,7 @@ export const NotificationDrawerListItem: React.FunctionComponent<NotificationDra
2628
isRead = false,
2729
// eslint-disable-next-line @typescript-eslint/no-unused-vars
2830
onClick = (event: React.MouseEvent) => undefined as any,
31+
readStateScreenReaderText,
2932
tabIndex = 0,
3033
variant = 'custom',
3134
...props
@@ -38,6 +41,14 @@ export const NotificationDrawerListItem: React.FunctionComponent<NotificationDra
3841
}
3942
}
4043
};
44+
45+
let readStateSRText;
46+
if (readStateScreenReaderText) {
47+
readStateSRText = readStateScreenReaderText;
48+
} else {
49+
readStateSRText = isRead ? 'read' : 'unread';
50+
}
51+
4152
return (
4253
<li
4354
{...props}
@@ -52,6 +63,7 @@ export const NotificationDrawerListItem: React.FunctionComponent<NotificationDra
5263
onClick={(e) => onClick(e)}
5364
onKeyDown={onKeyDown}
5465
>
66+
<span className="pf-v5-screen-reader">{readStateSRText}</span>
5567
{children}
5668
</li>
5769
);

packages/react-core/src/components/NotificationDrawer/__tests__/NotificationDrawerListItem.test.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,21 @@ describe('NotificationDrawerListItem', () => {
2121
expect(screen.getByRole('listitem')).toHaveClass('pf-m-hoverable');
2222
});
2323

24-
test('drawer list item with isRead applied', () => {
24+
test('drawer list item with isRead applied and screen reader text is set to read', () => {
2525
render(<NotificationDrawerListItem isRead />);
2626
expect(screen.getByRole('listitem')).toHaveClass('pf-m-read');
27+
expect(screen.getByRole('listitem')).toContainHTML('<span class="pf-v5-screen-reader">read</span>');
28+
29+
});
30+
31+
test('drawer list item has screen reader text set to unread by default', () => {
32+
render(<NotificationDrawerListItem />);
33+
expect(screen.getByRole('listitem')).toContainHTML('<span class="pf-v5-screen-reader">unread</span>');
34+
});
35+
36+
test('drawer list item screen reader textcan be customized', () => {
37+
render(<NotificationDrawerListItem readStateScreenReaderText="was read"/>);
38+
expect(screen.getByRole('listitem')).toContainHTML('<span class="pf-v5-screen-reader">was read</span>');
2739
});
2840
});
41+

packages/react-core/src/components/NotificationDrawer/__tests__/__snapshots__/NotificationDrawerHeader.test.tsx.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ exports[`NotificationDrawerHeader drawer header with count applied 1`] = `
1515
Notifications
1616
</h1>
1717
<span
18+
aria-live="polite"
1819
class="pf-v5-c-notification-drawer__header-status"
1920
>
2021
2 unread
@@ -38,6 +39,7 @@ exports[`NotificationDrawerHeader drawer header with custom unread text applied
3839
Notifications
3940
</h1>
4041
<span
42+
aria-live="polite"
4143
class="pf-v5-c-notification-drawer__header-status"
4244
>
4345
2 unread alerts

packages/react-core/src/components/NotificationDrawer/__tests__/__snapshots__/NotificationDrawerListItem.test.tsx.snap

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ exports[`NotificationDrawerListItem renders with PatternFly Core styles 1`] = `
55
<li
66
class="pf-v5-c-notification-drawer__list-item pf-m-hoverable pf-m-custom"
77
tabindex="0"
8-
/>
8+
>
9+
<span
10+
class="pf-v5-screen-reader"
11+
>
12+
unread
13+
</span>
14+
</li>
915
</DocumentFragment>
1016
`;

0 commit comments

Comments
 (0)