Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Props for toast container and close button aria-labels #239

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
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