Skip to content

Commit 8ff2476

Browse files
jgw96danbucholtz
authored andcommitted
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
1 parent 922a8a3 commit 8ff2476

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/components/toast/toast.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Component, ElementRef, Renderer, Output, EventEmitter} from '@angular/core';
1+
import {AfterViewInit, Component, ElementRef, EventEmitter, Output, Renderer} from '@angular/core';
22

33
import {ActionSheet, ActionSheetOptions} from '../action-sheet/action-sheet';
44
import {Animation} from '../../animations/animation';
@@ -158,7 +158,7 @@ const TOAST_POSITION_BOTTOM: string = 'bottom';
158158
'[attr.aria-describedby]': 'descId',
159159
},
160160
})
161-
class ToastCmp {
161+
class ToastCmp implements AfterViewInit {
162162
private d: any;
163163
private descId: string;
164164
private hdrId: string;
@@ -188,6 +188,16 @@ class ToastCmp {
188188
}
189189
}
190190

191+
ngAfterViewInit() {
192+
// if there's a `duration` set, automatically dismiss.
193+
if (this.d.duration) {
194+
this.dismissTimeout =
195+
setTimeout(() => {
196+
this.dismiss('backdrop');
197+
}, this.d.duration);
198+
}
199+
}
200+
191201
ionViewDidEnter() {
192202
const { activeElement }: any = document;
193203
if (activeElement) {
@@ -199,14 +209,6 @@ class ToastCmp {
199209
if (focusableEle) {
200210
focusableEle.focus();
201211
}
202-
203-
// if there's a `duration` set, automatically dismiss.
204-
if (this.d.duration) {
205-
this.dismissTimeout =
206-
setTimeout(() => {
207-
this.dismiss('backdrop');
208-
}, this.d.duration);
209-
}
210212
}
211213

212214
cbClick() {

0 commit comments

Comments
 (0)