diff --git a/packages/toast/src/ToastTimer.tsx b/packages/toast/src/ToastTimer.tsx index 190c1afbd..483448cc8 100644 --- a/packages/toast/src/ToastTimer.tsx +++ b/packages/toast/src/ToastTimer.tsx @@ -75,8 +75,10 @@ export const ToastTimer: FunctionComponent = ({ toast, index }) => { toastElement.addEventListener('mouseenter', handleMouseEnter) toastElement.addEventListener('mouseleave', handleMouseLeave) } - window.addEventListener('focus', handlePageFocus) - window.addEventListener('blur', handlePageBlur) + if (toast.pauseOnWindowBlur) { + window.addEventListener('focus', handlePageFocus) + window.addEventListener('blur', handlePageBlur) + } return () => { clearTimer() @@ -84,8 +86,10 @@ export const ToastTimer: FunctionComponent = ({ toast, index }) => { toastElement.removeEventListener('mouseenter', handleMouseEnter) toastElement.removeEventListener('mouseleave', handleMouseLeave) } - window.removeEventListener('focus', handlePageFocus) - window.removeEventListener('blur', handlePageBlur) + if (toast.pauseOnWindowBlur) { + window.removeEventListener('focus', handlePageFocus) + window.removeEventListener('blur', handlePageBlur) + } } }, [ clearTimer, diff --git a/packages/toast/src/toastStore.ts b/packages/toast/src/toastStore.ts index ba676842a..c3875799a 100644 --- a/packages/toast/src/toastStore.ts +++ b/packages/toast/src/toastStore.ts @@ -61,10 +61,11 @@ export const addToast = action(toastStore, 'addToast', (store: WritableAtom