googlearchive / paper-toast

A lightweight feedback about an operation in a small popup at the base of the screen on mobile and at the lower left on desktop.
17 stars 8 forks source link

autoCloseDisabled toast still dismisses automatically #18

Open chrisconover opened 9 years ago

chrisconover commented 9 years ago

I'm trying to create a paper-toast that is sticky in the UI until I explicitly tell it to close.

The docs suggest using the attribute autoCloseDisabled to accomplish this, but in my experience it doesn't have any effect and the toast automatically dismisses after 3 seconds.

Simple example: http://codepen.io/chrisconover/pen/zxoQXG

 Expected behavior: Click button and toast appears and stays on the screen.
 Actual behavior: Click button and toast appears for 3 seconds and then dismisses.

I realize that I can set the duration to a really high integer, but this seems like a hack.

Is anyone else running into this?

klebba commented 9 years ago

autoClosedDisabled does not seem to work for me either (0.5.2)

ChrisMcKenzie commented 9 years ago

I am experiencing the same issue. :cry: :+1:

wuxiaoying commented 9 years ago

From the docs it looks like autoCloseDisabled is defined as

By default, the toast will close automatically if the user taps outside it or presses the escape key. Disable this behavior by setting the autoCloseDisabled property to true.

That's actually related to closing from user actions, not the dismiss after the duration. (It's used in core-overlay)

The code looks like:

      openedChanged: function() {
        if (this.opened) {
          this.dismissJob = this.job(this.dismissJob, this.dismiss, this.duration);
        } else {
          this.dismissJob && this.dismissJob.stop();
          this.dismiss();
        }
      },

You can see that it always dismisses after the given duration regardless of autoCloseDisabled. From what I see you could either set an infinite duration, or the code would have to be like below, but I'm not sure if that was the author's intention.

      openedChanged: function() {
        if (this.opened) {
          if (this.autoCloseDisabled) return;
          this.dismissJob = this.job(this.dismissJob, this.dismiss, this.duration);
        } else {
          this.dismissJob && this.dismissJob.stop();
          this.dismiss();
        }
      },

The correct way to do is probably to add another attribute like disableDismiss that does this instead.

dominik0711 commented 9 years ago

Same here in Polymer version 0.5.5. A dirty workaround is to set duration to a stupid large milliseconds value!!!

cskinner35 commented 7 years ago

Simply give the toast an attribute of duration="0". Then, whenever you open the toast, it will stick on the screen, unless you press the Esc key, for which Polymer has graciously given us an attribute called noCancelOnEscKey

Here's their documentation: https://www.webcomponents.org/element/PolymerElements/paper-toast/paper-toast