From c1641810294a48a5d0b08e01ce86c989a38493f1 Mon Sep 17 00:00:00 2001 From: Justin Max Langfan Date: Tue, 12 Nov 2024 09:45:18 -0500 Subject: [PATCH 1/3] [core] fix: get toasters for timeout Infinity to match that of timeout 0 behavior (#6742) --- packages/core/src/components/toast/toast2.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/core/src/components/toast/toast2.tsx b/packages/core/src/components/toast/toast2.tsx index f726528cb6..447f8f170f 100644 --- a/packages/core/src/components/toast/toast2.tsx +++ b/packages/core/src/components/toast/toast2.tsx @@ -44,7 +44,8 @@ export const Toast2 = React.forwardRef((props, ref) 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; + // Per github, issue 6742: "timeout: Infinity should also behave the same as timeout: 0" + const isTimeoutEnabled = timeout != null && timeout > 0 && timeout !== Infinity; // timeout is triggered & cancelled by updating `isTimeoutStarted` state useTimeout( From 540b95e8f69a3ea6a0232d63447ad704d2c28349 Mon Sep 17 00:00:00 2001 From: Justin Max Langfan Date: Tue, 12 Nov 2024 13:14:53 -0500 Subject: [PATCH 2/3] [core] test: add test case for Toast timeout={Infinity} behavior --- packages/core/test/toast/toast2Tests.tsx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/core/test/toast/toast2Tests.tsx b/packages/core/test/toast/toast2Tests.tsx index adab602202..6e843fea7a 100644 --- a/packages/core/test/toast/toast2Tests.tsx +++ b/packages/core/test/toast/toast2Tests.tsx @@ -98,5 +98,13 @@ describe("", () => { done(); }, 20); }); + + it("timeout={Infinity} behaves same as timeout={0} and does not trigger onDismiss", done => { + mount(); + setTimeout(() => { + assert.isTrue(handleDismiss.notCalled, "onDismiss was called when it should not have been"); + done(); + }, 20); + }); }); }); From 64db9c86f474843c455ad507cbd4212b50bee152 Mon Sep 17 00:00:00 2001 From: Justin Max Langfan Date: Tue, 19 Nov 2024 13:40:29 -0500 Subject: [PATCH 3/3] Remove redundant comments and update documentation per review --- packages/core/src/components/toast/toast2.tsx | 2 -- packages/core/src/components/toast/toastProps.ts | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/core/src/components/toast/toast2.tsx b/packages/core/src/components/toast/toast2.tsx index 447f8f170f..3d7d54615c 100644 --- a/packages/core/src/components/toast/toast2.tsx +++ b/packages/core/src/components/toast/toast2.tsx @@ -43,8 +43,6 @@ 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)." - // Per github, issue 6742: "timeout: Infinity should also behave the same as timeout: 0" const isTimeoutEnabled = timeout != null && timeout > 0 && timeout !== Infinity; // timeout is triggered & cancelled by updating `isTimeoutStarted` state diff --git a/packages/core/src/components/toast/toastProps.ts b/packages/core/src/components/toast/toastProps.ts index 63cc02577d..5a70be7385 100644 --- a/packages/core/src/components/toast/toastProps.ts +++ b/packages/core/src/components/toast/toastProps.ts @@ -47,7 +47,7 @@ export interface ToastProps extends Props, IntentProps { /** * Milliseconds to wait before automatically dismissing toast. - * Providing a value less than or equal to 0 will disable the timeout (this is discouraged). + * Providing a value less than or equal to 0 or Infinity will disable the timeout (this is discouraged). * * @default 5000 */