Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EuiGlobalToastList] Add configurable role prop and default to log role #7328

Merged
merged 4 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ exports[`EuiGlobalToastList is rendered 1`] = `
aria-live="polite"
class="euiGlobalToastList testClass1 testClass2 emotion-euiGlobalToastList-right-euiTestCss"
data-test-subj="test subject string"
role="region"
role="log"
/>
`;

exports[`EuiGlobalToastList props side can be changed to left 1`] = `
<div
aria-live="polite"
class="euiGlobalToastList emotion-euiGlobalToastList-left"
role="region"
role="log"
>
<div
class="euiToast euiGlobalToastListItem emotion-euiToast-success-euiGlobalToastListItem"
Expand Down Expand Up @@ -117,7 +117,7 @@ exports[`EuiGlobalToastList props toasts is rendered 1`] = `
<div
aria-live="polite"
class="euiGlobalToastList emotion-euiGlobalToastList-right"
role="region"
role="log"
>
<div
class="euiToast euiGlobalToastListItem emotion-euiToast-success-euiGlobalToastListItem"
Expand Down
13 changes: 13 additions & 0 deletions src/components/toast/global_toast_list.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -271,5 +271,18 @@ describe('EuiGlobalToastList', () => {
expect(sharedProps.dismissToast).toHaveBeenCalledTimes(TOAST_COUNT);
});
});

test('role', () => {
const { queryByRole } = render(
<EuiGlobalToastList
dismissToast={() => {}}
toastLifeTimeMs={5}
role="alert"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Awesome. Role override is a nice escape hatch in use cases where we need to get users' attention more assertively.

/>
);

expect(queryByRole('alert')).toBeInTheDocument();
expect(queryByRole('log')).not.toBeInTheDocument();
});
});
});
17 changes: 14 additions & 3 deletions src/components/toast/global_toast_list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

import React, {
FunctionComponent,
ReactChild,
HTMLAttributes,
ReactNode,
useCallback,
useEffect,
useRef,
Expand Down Expand Up @@ -40,7 +41,7 @@ export const CLEAR_ALL_TOASTS_THRESHOLD_DEFAULT = 3;

export interface Toast extends EuiToastProps {
id: string;
text?: ReactChild;
text?: ReactNode;
toastLifeTimeMs?: number;
}

Expand All @@ -63,6 +64,16 @@ export interface EuiGlobalToastListProps extends CommonProps {
* Optional callback that fires when a user clicks the "Clear all" button.
*/
onClearAllToasts?: () => void;
/**
* Defaults to the [log role](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/log_role).
*
* The [alert role](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/alert_role)
* can be considered only if *all* toasts in this list will require immediate user attention.
* Several alerts at once, and unnecessary alerts, will a create bad screen reader user experience.
*
* @default log
*/
role?: HTMLAttributes<HTMLElement>['role'];
}

export const EuiGlobalToastList: FunctionComponent<EuiGlobalToastListProps> = ({
Expand Down Expand Up @@ -345,7 +356,7 @@ export const EuiGlobalToastList: FunctionComponent<EuiGlobalToastListProps> = ({
return (
<div
aria-live="polite"
role="region"
role="log"
ref={listElement}
css={cssStyles}
className={classes}
Expand Down
5 changes: 5 additions & 0 deletions upcoming_changelogs/7328.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- Added a configurable `role` prop to `EuiGlobalToastList`

**Accessibility**

- `EuiGlobalToastList` now defaults to a `log` role. If your toasts will always require immediate user action, consider (with caution) using the `alert` role instead.
Loading