From cffa354730f880a9ef5cd2644f8c4c7c72821758 Mon Sep 17 00:00:00 2001 From: Brandon Cheng Date: Thu, 2 May 2024 23:17:10 -0400 Subject: [PATCH] Fix toasters immediately closing on hover if timeout is set to 0 --- packages/core/src/components/toast/toast2.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/core/src/components/toast/toast2.tsx b/packages/core/src/components/toast/toast2.tsx index d1c08212ca..d365a40843 100644 --- a/packages/core/src/components/toast/toast2.tsx +++ b/packages/core/src/components/toast/toast2.tsx @@ -43,12 +43,15 @@ export const Toast2 = React.forwardRef((props, ref) const startTimeout = React.useCallback(() => setIsTimeoutStarted(true), []); const clearTimeout = React.useCallback(() => setIsTimeoutStarted(false), []); + // Per docs: "Providing a value less than or equal to 0 will disable the timeout (this is discouraged)." + const isTimeoutEnabled = timeout != null && timeout > 0; + // timeout is triggered & cancelled by updating `isTimeoutStarted` state useTimeout( () => { triggerDismiss(true); }, - isTimeoutStarted && timeout !== undefined ? timeout : null, + isTimeoutStarted && isTimeoutEnabled ? timeout : null, ); // start timeout on mount or change, cancel on unmount