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

Toast update with key should also update timeout option #3107

Closed
tgreen7 opened this issue Nov 1, 2018 · 1 comment
Closed

Toast update with key should also update timeout option #3107

tgreen7 opened this issue Nov 1, 2018 · 1 comment

Comments

@tgreen7
Copy link
Contributor

tgreen7 commented Nov 1, 2018

Environment

Steps to reproduce

import { Toaster, Position } from "@blueprintjs/core";

const toastr = Toaster.create({
  position: Position.TOP
});

let timesShown = 1;
    const key = toastr.show({
      message: `shown ${timesShown}`,
      timeout: 100000
    });

    const interval = setInterval(() => {
      timesShown++;
      toastr.show(
        {
          message: `shown ${timesShown}`,
          timeout: timesShown === 10 ? 3000 : 100000
        },
        key
      );
      if (timesShown === 10) {
        clearInterval(interval);
      }
    }, 1000);

Actual behavior

The toastr keeps the original timeout of 100 seconds meaning that after finishing it still won't dismiss automatically

Expected behavior

That updating the timeout will make the toastr dismiss when the new timeout triggers

Possible solution

in the toastr code

 public componentDidUpdate(prevProps: IToastProps) {
        if (prevProps.timeout <= 0 && this.props.timeout > 0) {
            this.startTimeout();
        } else if (prevProps.timeout > 0 && this.props.timeout <= 0) {
            this.clearTimeouts();
        }
    }

that first check for prevProps.timeout <= 0 seems wrong. It should start the timeout regardless so that the newly passed timeout prop will be used.

@giladgray
Copy link
Contributor

@tgreen7 yep seems a legit bug!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants