Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 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 @@ -12,6 +12,7 @@ import {
cls,
getBoolean,
getBooleanAsString,
getNotificationRole,
stringPropVisible
} from '../../utils';
import DBButton from '../button/button.lite';
Expand Down Expand Up @@ -41,6 +42,7 @@ export default function DBNotification(props: DBNotificationProps) {
ref={_ref}
id={props.id}
class={cls('db-notification', props.className)}
role={getNotificationRole(props.semantic)}
aria-live={props.ariaLive}
Comment on lines +45 to 46
Copy link
Contributor

Choose a reason for hiding this comment

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

You could set role="alert" and aria-live="off", which is contradictory (https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Guides/Live_regions).
You could derive a default aria-live from the role only when ariaLive isn’t provided (alert --> assertive, status -->polite) to avoid invalid combinations and maximize a11y compatibility.

something like

const role = getNotificationRole(props.semantic);
const derivedLive =
role === 'alert' ? 'assertive' :
role === 'status' ? 'polite' :
undefined;

data-semantic={props.semantic}
data-variant={props.variant}
Expand Down
18 changes: 18 additions & 0 deletions packages/components/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,21 @@ export const isKeyboardEvent = <T>(
event?: ClickEvent<T> | GeneralKeyboardEvent<T>
): event is GeneralKeyboardEvent<T> =>
(event as GeneralKeyboardEvent<T>).key !== undefined;

/**
* Maps semantic values to appropriate ARIA roles for notifications
* @param semantic - The semantic type of the notification
* @returns The appropriate ARIA role or undefined for default behavior
*/
export const getNotificationRole = (semantic?: string): string | undefined => {
switch (semantic) {
case 'critical':
case 'warning':
return 'alert';
case 'informational':
case 'successful':
return 'status';
default:
return undefined;
}
};