Skip to content

Commit

Permalink
feat: allow user to activate action with keyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinmulier committed Dec 19, 2024
1 parent d032b34 commit 053607a
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion packages/ui/src/atoms/toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export const customToast = (
className: textVariants({
mode: options.mode,
}),
onClick: options.onClick,
}),
{
autoClose: options.time || 5000,
Expand Down Expand Up @@ -172,10 +173,26 @@ export const customToast = (
const ToastContent = ({
message,
className,
onClick,
}: {
message: string;
className: string;
}) => <span className={className}>{message}</span>;
onClick?: () => void;
}) => (
<span
className={className}
onKeyDown={(e) => {
if (onClick && (e.key === 'Enter' || e.key === ' ')) {
e.preventDefault();
onClick();
}
}}
role={onClick ? 'button' : undefined}
tabIndex={onClick ? 0 : undefined}
>
{message}
</span>
);

const ToastCloseButton = ({
closeToast,
Expand Down

0 comments on commit 053607a

Please sign in to comment.