diff --git a/src/components/Toast.tsx b/src/components/Toast.tsx index 3cfa6f4d..2737c10c 100644 --- a/src/components/Toast.tsx +++ b/src/components/Toast.tsx @@ -41,7 +41,8 @@ export const Toast: React.FC = props => { isIn, isLoading, closeOnClick, - theme + theme, + onButtonClose } = props; const defaultClassName = cx( `${Default.CSS_NAMESPACE}__toast`, @@ -65,7 +66,14 @@ export const Toast: React.FC = props => { const icon = getIcon(props); const isProgressControlled = !!progress || !autoClose; - const closeButtonProps = { closeToast, type, theme }; + const handleButtonClose = () => { + if (onButtonClose) { + onButtonClose(); + } + closeToast(); + }; + + const closeButtonProps = { closeToast: handleButtonClose, type, theme }; let Close: React.ReactNode = null; if (closeButton === false) { diff --git a/src/components/ToastContainer.tsx b/src/components/ToastContainer.tsx index 049a889f..43f9cb01 100644 --- a/src/components/ToastContainer.tsx +++ b/src/components/ToastContainer.tsx @@ -123,6 +123,7 @@ export function ToastContainer(props: ToastContainerProps) { toastProps.containerId )} style={toastProps.style} + onButtonClose={toastProps.onButtonClose} key={`toast-${toastProps.key}`} > {content} diff --git a/src/types.ts b/src/types.ts index a7f2e5f1..7cf7931d 100644 --- a/src/types.ts +++ b/src/types.ts @@ -315,6 +315,7 @@ export interface ToastProps extends ToastOptions { type: TypeOptions; collapseAll: () => void; stacked?: boolean; + onButtonClose?: () => void; } /**