Skip to content

Commit

Permalink
Props for toast container and close button aria-labels (#239)
Browse files Browse the repository at this point in the history
  • Loading branch information
rodymolenaar authored Nov 29, 2023
1 parent 167b92d commit 1d37008
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ interface ToastProps {
descriptionClassName?: string;
loadingIcon?: React.ReactNode;
classNames?: ToastClassnames;
closeButtonAriaLabel?: string;
}

function cn(...classes: (string | undefined)[]) {
Expand Down Expand Up @@ -81,6 +82,7 @@ const Toast = (props: ToastProps) => {
loadingIcon: loadingIconProp,
expandByDefault,
classNames,
closeButtonAriaLabel = 'Close toast',
} = props;
const [mounted, setMounted] = React.useState(false);
const [removed, setRemoved] = React.useState(false);
Expand Down Expand Up @@ -325,7 +327,7 @@ const Toast = (props: ToastProps) => {
>
{closeButton && !toast.jsx ? (
<button
aria-label="Close toast"
aria-label={closeButtonAriaLabel}
data-disabled={disabled}
data-close-button
onClick={
Expand Down Expand Up @@ -450,6 +452,7 @@ const Toaster = (props: ToasterProps) => {
dir = getDocumentDirection(),
gap,
loadingIcon,
containerAriaLabel = 'Notifications',
} = props;
const [toasts, setToasts] = React.useState<ToastT[]>([]);
const possiblePositions = React.useMemo(() => {
Expand Down Expand Up @@ -581,7 +584,7 @@ const Toaster = (props: ToasterProps) => {

return (
// Remove item from normal navigation flow, only available via hotkey
<section aria-label={`Notifications ${hotkeyLabel}`} tabIndex={-1}>
<section aria-label={`${containerAriaLabel} ${hotkeyLabel}`} tabIndex={-1}>
{possiblePositions.map((position, index) => {
const [y, x] = position.split('-');
return (
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export interface ToasterProps {
offset?: string | number;
dir?: 'rtl' | 'ltr' | 'auto';
loadingIcon?: React.ReactNode;
containerAriaLabel?: string;
}

export enum SwipeStateTypes {
Expand Down

0 comments on commit 1d37008

Please sign in to comment.