Skip to content

Commit 070b802

Browse files
authored
[core] fix: toasters closing immediately on hover if timeout is set to 0 (#6783)
1 parent 488658d commit 070b802

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

packages/core/src/components/toast/toast2.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,15 @@ export const Toast2 = React.forwardRef<HTMLDivElement, ToastProps>((props, ref)
4343
const startTimeout = React.useCallback(() => setIsTimeoutStarted(true), []);
4444
const clearTimeout = React.useCallback(() => setIsTimeoutStarted(false), []);
4545

46+
// Per docs: "Providing a value less than or equal to 0 will disable the timeout (this is discouraged)."
47+
const isTimeoutEnabled = timeout != null && timeout > 0;
48+
4649
// timeout is triggered & cancelled by updating `isTimeoutStarted` state
4750
useTimeout(
4851
() => {
4952
triggerDismiss(true);
5053
},
51-
isTimeoutStarted && timeout !== undefined ? timeout : null,
54+
isTimeoutStarted && isTimeoutEnabled ? timeout : null,
5255
);
5356

5457
// start timeout on mount or change, cancel on unmount

0 commit comments

Comments
 (0)