From 44f343d3dcd7d9b056c3fc6d6a1b23b7a172861c Mon Sep 17 00:00:00 2001 From: "Manu Mtz.-Almeida" Date: Sat, 24 Mar 2018 03:25:16 +0100 Subject: [PATCH] fix(toast): dismiss timeout --- core/src/components/toast/toast.tsx | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/core/src/components/toast/toast.tsx b/core/src/components/toast/toast.tsx index 774de33fee..796effe3a6 100644 --- a/core/src/components/toast/toast.tsx +++ b/core/src/components/toast/toast.tsx @@ -22,6 +22,8 @@ import mdLeaveAnimation from './animations/md.leave'; }) export class Toast implements OverlayInterface { + private durationTimeout: any; + presented = false; @Element() el: HTMLElement; @@ -142,12 +144,12 @@ export class Toast implements OverlayInterface { * Present the toast overlay after it has been created. */ @Method() - present(): Promise { - return present(this, 'toastEnter', iosEnterAnimation, mdEnterAnimation, this.position).then(() => { - if (this.duration) { - setTimeout(() => this.dismiss(), this.duration); - } - }); + async present(): Promise { + await present(this, 'toastEnter', iosEnterAnimation, mdEnterAnimation, this.position); + + if (this.duration > 0) { + this.durationTimeout = setTimeout(() => this.dismiss(), this.duration); + } } /** @@ -155,6 +157,9 @@ export class Toast implements OverlayInterface { */ @Method() dismiss(data?: any, role?: string): Promise { + if (this.durationTimeout) { + clearTimeout(this.durationTimeout); + } return dismiss(this, data, role, 'toastLeave', iosLeaveAnimation, mdLeaveAnimation, this.position); }