Skip to content

Commit

Permalink
fix(Notification Drawer): Added screen reader text for notification d…
Browse files Browse the repository at this point in the history
…rawer item read state
  • Loading branch information
tlabaj committed Sep 6, 2023
1 parent 3828124 commit 4b4c4c9
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1093,10 +1093,7 @@ exports[`Nav Nav List with flyout 1`] = `
</button>
<div
class=""
data-popper-escaped="true"
data-popper-placement="right-start"
data-popper-reference-hidden="true"
style="position: absolute; left: 0px; top: 0px; z-index: 9999; opacity: 0; transition: opacity 0ms cubic-bezier(.54, 1.5, .38, 1.11); min-width: 0px; transform: translate(0px, 0px);"
style="position: absolute; left: 0px; top: 0px; z-index: 9999; opacity: 0; transition: opacity 0ms cubic-bezier(.54, 1.5, .38, 1.11); min-width: 0px;"
>
<div>
Flyout test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export interface NotificationDrawerListItemProps extends React.HTMLProps<HTMLLIE
isRead?: boolean;
/** Callback for when a list item is clicked */
onClick?: (event: any) => void;
/** Read state screen reader text */
readStateScreenReaderText?: string;
/** Tab index for the list item */
tabIndex?: number;
/** Variant indicates the severity level */
Expand All @@ -26,6 +28,7 @@ export const NotificationDrawerListItem: React.FunctionComponent<NotificationDra
isRead = false,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
onClick = (event: React.MouseEvent) => undefined as any,
readStateScreenReaderText,
tabIndex = 0,
variant = 'custom',
...props
Expand All @@ -40,6 +43,14 @@ export const NotificationDrawerListItem: React.FunctionComponent<NotificationDra
}
}
};

let readStateSRText;
if (readStateScreenReaderText) {
readStateSRText = readStateScreenReaderText;
} else {
readStateSRText = isRead ? 'read' : 'unread';
}

return (
<li
{...props}
Expand All @@ -54,6 +65,7 @@ export const NotificationDrawerListItem: React.FunctionComponent<NotificationDra
onClick={(e) => onClick(e)}
onKeyDown={onKeyDown}
>
<span className="pf-v5-screen-reader">{readStateSRText}</span>
{children}
</li>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,21 @@ describe('NotificationDrawerListItem', () => {
expect(screen.getByRole('listitem')).toHaveClass('pf-m-hoverable');
});

test('drawer list item with isRead applied', () => {
test('drawer list item with isRead applied and screen reader text is set to read', () => {
render(<NotificationDrawerListItem isRead />);
expect(screen.getByRole('listitem')).toHaveClass('pf-m-read');
expect(screen.getByRole('listitem')).toContainHTML('<span class="pf-v5-screen-reader">read</span>');

});

test('drawer list item has screen reader text set to unread by default', () => {
render(<NotificationDrawerListItem />);
expect(screen.getByRole('listitem')).toContainHTML('<span class="pf-v5-screen-reader">unread</span>');
});

test('drawer list item screen reader textcan be customized', () => {
render(<NotificationDrawerListItem readStateScreenReaderText="was read"/>);
expect(screen.getByRole('listitem')).toContainHTML('<span class="pf-v5-screen-reader">was read</span>');
});
});

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ exports[`NotificationDrawerListItem renders with PatternFly Core styles 1`] = `
<li
class="pf-v5-c-notification-drawer__list-item pf-m-hoverable pf-m-custom"
tabindex="0"
/>
>
<span
class="pf-v5-screen-reader"
>
unread
</span>
</li>
</DocumentFragment>
`;

0 comments on commit 4b4c4c9

Please sign in to comment.