From 8ff2476cc323c7866f80b90455a6fad4a6387a4c Mon Sep 17 00:00:00 2001 From: Justin Willis Date: Thu, 9 Jun 2016 13:02:53 -0500 Subject: [PATCH] fix(toast): close toasts when two or more are open (#6814) * fix(toast): close toast when two or more are open * fix(toast): abc order imports * fix(toast): move focus code into ionic event --- src/components/toast/toast.ts | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/components/toast/toast.ts b/src/components/toast/toast.ts index e422aaae2e9..cf36d0906b1 100644 --- a/src/components/toast/toast.ts +++ b/src/components/toast/toast.ts @@ -1,4 +1,4 @@ -import {Component, ElementRef, Renderer, Output, EventEmitter} from '@angular/core'; +import {AfterViewInit, Component, ElementRef, EventEmitter, Output, Renderer} from '@angular/core'; import {ActionSheet, ActionSheetOptions} from '../action-sheet/action-sheet'; import {Animation} from '../../animations/animation'; @@ -158,7 +158,7 @@ const TOAST_POSITION_BOTTOM: string = 'bottom'; '[attr.aria-describedby]': 'descId', }, }) -class ToastCmp { +class ToastCmp implements AfterViewInit { private d: any; private descId: string; private hdrId: string; @@ -188,6 +188,16 @@ class ToastCmp { } } + ngAfterViewInit() { + // if there's a `duration` set, automatically dismiss. + if (this.d.duration) { + this.dismissTimeout = + setTimeout(() => { + this.dismiss('backdrop'); + }, this.d.duration); + } + } + ionViewDidEnter() { const { activeElement }: any = document; if (activeElement) { @@ -199,14 +209,6 @@ class ToastCmp { if (focusableEle) { focusableEle.focus(); } - - // if there's a `duration` set, automatically dismiss. - if (this.d.duration) { - this.dismissTimeout = - setTimeout(() => { - this.dismiss('backdrop'); - }, this.d.duration); - } } cbClick() {