Skip to content

Commit 1d37008

Browse files
authored
Props for toast container and close button aria-labels (#239)
1 parent 167b92d commit 1d37008

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/index.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ interface ToastProps {
5151
descriptionClassName?: string;
5252
loadingIcon?: React.ReactNode;
5353
classNames?: ToastClassnames;
54+
closeButtonAriaLabel?: string;
5455
}
5556

5657
function cn(...classes: (string | undefined)[]) {
@@ -81,6 +82,7 @@ const Toast = (props: ToastProps) => {
8182
loadingIcon: loadingIconProp,
8283
expandByDefault,
8384
classNames,
85+
closeButtonAriaLabel = 'Close toast',
8486
} = props;
8587
const [mounted, setMounted] = React.useState(false);
8688
const [removed, setRemoved] = React.useState(false);
@@ -325,7 +327,7 @@ const Toast = (props: ToastProps) => {
325327
>
326328
{closeButton && !toast.jsx ? (
327329
<button
328-
aria-label="Close toast"
330+
aria-label={closeButtonAriaLabel}
329331
data-disabled={disabled}
330332
data-close-button
331333
onClick={
@@ -450,6 +452,7 @@ const Toaster = (props: ToasterProps) => {
450452
dir = getDocumentDirection(),
451453
gap,
452454
loadingIcon,
455+
containerAriaLabel = 'Notifications',
453456
} = props;
454457
const [toasts, setToasts] = React.useState<ToastT[]>([]);
455458
const possiblePositions = React.useMemo(() => {
@@ -581,7 +584,7 @@ const Toaster = (props: ToasterProps) => {
581584

582585
return (
583586
// Remove item from normal navigation flow, only available via hotkey
584-
<section aria-label={`Notifications ${hotkeyLabel}`} tabIndex={-1}>
587+
<section aria-label={`${containerAriaLabel} ${hotkeyLabel}`} tabIndex={-1}>
585588
{possiblePositions.map((position, index) => {
586589
const [y, x] = position.split('-');
587590
return (

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ export interface ToasterProps {
9393
offset?: string | number;
9494
dir?: 'rtl' | 'ltr' | 'auto';
9595
loadingIcon?: React.ReactNode;
96+
containerAriaLabel?: string;
9697
}
9798

9899
export enum SwipeStateTypes {

0 commit comments

Comments
 (0)