From d1b6619c7264cd67de11ef4f8ad2bb2c8cc04277 Mon Sep 17 00:00:00 2001 From: Jeff Huang Date: Wed, 24 Jan 2024 01:31:11 -0500 Subject: [PATCH] fix: make closeButton option in toast take precedence over Toaster (#309) --- src/index.tsx | 10 +++++++--- src/types.ts | 1 + website/src/pages/toast.mdx | 2 +- website/src/pages/toaster.mdx | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index a1a0e9a..e8b8a41 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -44,7 +44,7 @@ const Toast = (props: ToastProps) => { toasts, expanded, removeToast, - closeButton, + closeButton: closeButtonFromToaster, style, cancelButtonStyle, actionButtonStyle, @@ -77,6 +77,10 @@ const Toast = (props: ToastProps) => { () => heights.findIndex((height) => height.toastId === toast.id) || 0, [heights, toast.id], ); + const closeButton = React.useMemo( + () => toast.closeButton ?? closeButtonFromToaster, + [toast.closeButton, closeButtonFromToaster], + ); const duration = React.useMemo( () => toast.duration || durationFromToaster || TOAST_LIFETIME, [toast.duration, durationFromToaster], @@ -295,7 +299,7 @@ const Toast = (props: ToastProps) => { } }} > - {(closeButton || toast.closeButton) && !toast.jsx ? ( + {closeButton && !toast.jsx ? (