Skip to content

Commit

Permalink
[core] fix: toasters closing immediately on hover if timeout is set…
Browse files Browse the repository at this point in the history
… to 0 (#6783)
  • Loading branch information
gluxon authored May 3, 2024
1 parent 488658d commit 070b802
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/core/src/components/toast/toast2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,15 @@ export const Toast2 = React.forwardRef<HTMLDivElement, ToastProps>((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
Expand Down

1 comment on commit 070b802

@svc-palantir-github
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[core] fix: toasters closing immediately on hover if `timeout` is set to 0 (#6783)

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

Please sign in to comment.