Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] fix: get toasters timeout Infinity to match behavior of timeout 0 #7059

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions packages/core/src/components/toast/toast2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ 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;
const isTimeoutEnabled = timeout != null && timeout > 0 && timeout !== Infinity;

// timeout is triggered & cancelled by updating `isTimeoutStarted` state
useTimeout(
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/components/toast/toastProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Providing a value less than or equal to 0 or Infinity will disable the timeout (this is discouraged).
* Setting this to Infinity or a value less than or equal to 0 will disable the timeout (this is discouraged).

Minor nit to make sure that this is clear that we're not referring to values less than infinity

Copy link
Author

Choose a reason for hiding this comment

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

Great! Glad to help.

*
* @default 5000
*/
Expand Down
8 changes: 8 additions & 0 deletions packages/core/test/toast/toast2Tests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,13 @@ describe("<Toast2>", () => {
done();
}, 20);
});

it("timeout={Infinity} behaves same as timeout={0} and does not trigger onDismiss", done => {
mount(<Toast2 message="Hello" onDismiss={handleDismiss} timeout={Infinity} />);
setTimeout(() => {
assert.isTrue(handleDismiss.notCalled, "onDismiss was called when it should not have been");
done();
}, 20);
});
});
});