Skip to content

An opinionated toast component for React.

feat(toaster): add support for custom aria labels (#704)

Hirotomo Yamada8c0ce1ee5cc1
diff --git a/src/index.tsx b/src/index.tsx
index f64a469..cc4dedc 100644
--- a/src/index.tsx
+++ b/src/index.tsx
@@ -610,6 +610,7 @@ const Toaster = React.forwardRef<HTMLElement, ToasterProps>(function Toaster(pro
dir = getDocumentDirection(),
gap = GAP,
icons,
+ customAriaLabel,
containerAriaLabel = 'Notifications',
} = props;
const [toasts, setToasts] = React.useState<ToastT[]>([]);
@@ -773,7 +774,7 @@ const Toaster = React.forwardRef<HTMLElement, ToasterProps>(function Toaster(pro
// Remove item from normal navigation flow, only available via hotkey
<section
ref={ref}
- aria-label={`${containerAriaLabel} ${hotkeyLabel}`}
+ aria-label={customAriaLabel ?? `${containerAriaLabel} ${hotkeyLabel}`}
tabIndex={-1}
aria-live="polite"
aria-relevant="additions text"
diff --git a/src/types.ts b/src/types.ts
index 79b9bdc..e74740d 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -145,6 +145,7 @@ export interface ToasterProps {
dir?: 'rtl' | 'ltr' | 'auto';
swipeDirections?: SwipeDirection[];
icons?: ToastIcons;
+ customAriaLabel?: string;
containerAriaLabel?: string;
}