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 2 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: 2 additions & 1 deletion packages/core/src/components/toast/toast2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ export const Toast2 = React.forwardRef<HTMLDivElement, ToastProps>((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"
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can remove both these comments, they don't add anything that the code does not provide here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, lets update the docs for the timeout prop to mention the behavior of Infinity.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the feedback! I've removed the comments and updated the timeout prop documentation to include the Infinity behavior. Let me know if you'd like me to make any other changes.

const isTimeoutEnabled = timeout != null && timeout > 0 && timeout !== Infinity;

// timeout is triggered & cancelled by updating `isTimeoutStarted` state
useTimeout(
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);
});
});
});