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

fix(toast): close toasts when two or more are open #6814

Merged
merged 4 commits into from
Jun 9, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions src/components/toast/toast.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -188,6 +188,16 @@ class ToastCmp {
}
}

ngAfterViewInit() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Putting the focus in AfterViewInit may be too soon before the element can receive focus in the DOM.

// 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) {
Expand All @@ -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() {
Expand Down