Skip to content

Commit 6271418

Browse files
Copilotmfranzke
andcommitted
Changes before error encountered
Co-authored-by: mfranzke <787658+mfranzke@users.noreply.github.com>
1 parent b8b6fc5 commit 6271418

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

packages/components/src/components/notification/notification.lite.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
cls,
1313
getBoolean,
1414
getBooleanAsString,
15+
getNotificationRole,
1516
stringPropVisible
1617
} from '../../utils';
1718
import DBButton from '../button/button.lite';
@@ -41,6 +42,7 @@ export default function DBNotification(props: DBNotificationProps) {
4142
ref={_ref}
4243
id={props.id}
4344
class={cls('db-notification', props.className)}
45+
role={getNotificationRole(props.semantic)}
4446
aria-live={props.ariaLive}
4547
data-semantic={props.semantic}
4648
data-variant={props.variant}

packages/components/src/utils/index.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,21 @@ export const isKeyboardEvent = <T>(
157157
event?: ClickEvent<T> | GeneralKeyboardEvent<T>
158158
): event is GeneralKeyboardEvent<T> =>
159159
(event as GeneralKeyboardEvent<T>).key !== undefined;
160+
161+
/**
162+
* Maps semantic values to appropriate ARIA roles for notifications
163+
* @param semantic - The semantic type of the notification
164+
* @returns The appropriate ARIA role or undefined for default behavior
165+
*/
166+
export const getNotificationRole = (semantic?: string): string | undefined => {
167+
switch (semantic) {
168+
case 'critical':
169+
case 'warning':
170+
return 'alert';
171+
case 'informational':
172+
case 'successful':
173+
return 'status';
174+
default:
175+
return undefined;
176+
}
177+
};

0 commit comments

Comments
 (0)