fix(toast): adds role timeout and cancel

fixes #15477
This commit is contained in:
Manu Mtz.-Almeida
2018-09-07 16:44:36 +02:00
parent efb99cb085
commit 2f2a255436

View File

@ -1,4 +1,4 @@
import { Component, Element, Event, EventEmitter, Listen, Method, Prop } from '@stencil/core'; import { Component, Element, Event, EventEmitter, Method, Prop } from '@stencil/core';
import { Animation, AnimationBuilder, Config, Mode, OverlayEventDetail, OverlayInterface } from '../../interface'; import { Animation, AnimationBuilder, Config, Mode, OverlayEventDetail, OverlayInterface } from '../../interface';
import { dismiss, eventMethod, present } from '../../utils/overlays'; import { dismiss, eventMethod, present } from '../../utils/overlays';
@ -131,14 +131,6 @@ export class Toast implements OverlayInterface {
this.ionToastDidUnload.emit(); this.ionToastDidUnload.emit();
} }
@Listen('ionDismiss')
protected onDismiss(ev: UIEvent) {
ev.stopPropagation();
ev.preventDefault();
return this.dismiss();
}
/** /**
* Present the toast overlay after it has been created. * Present the toast overlay after it has been created.
*/ */
@ -147,7 +139,7 @@ export class Toast implements OverlayInterface {
await present(this, 'toastEnter', iosEnterAnimation, mdEnterAnimation, this.position); await present(this, 'toastEnter', iosEnterAnimation, mdEnterAnimation, this.position);
if (this.duration > 0) { if (this.duration > 0) {
this.durationTimeout = setTimeout(() => this.dismiss(), this.duration); this.durationTimeout = setTimeout(() => this.dismiss(undefined, 'timeout'), this.duration);
} }
} }
@ -163,9 +155,7 @@ export class Toast implements OverlayInterface {
} }
/** /**
* Returns a promise that resolves when the toast did dismiss. It also accepts a callback * Returns a promise that resolves when the toast did dismiss.
* that is called in the same circustances.
*
*/ */
@Method() @Method()
onDidDismiss(): Promise<OverlayEventDetail> { onDidDismiss(): Promise<OverlayEventDetail> {
@ -173,9 +163,7 @@ export class Toast implements OverlayInterface {
} }
/** /**
* Returns a promise that resolves when the toast will dismiss. It also accepts a callback * Returns a promise that resolves when the toast will dismiss.
* that is called in the same circustances.
*
*/ */
@Method() @Method()
onWillDismiss(): Promise<OverlayEventDetail> { onWillDismiss(): Promise<OverlayEventDetail> {
@ -206,7 +194,7 @@ export class Toast implements OverlayInterface {
<div class="toast-message">{this.message}</div> <div class="toast-message">{this.message}</div>
} }
{this.showCloseButton && {this.showCloseButton &&
<ion-button fill="clear" color="light" ion-activable class="toast-button" onClick={() => this.dismiss()}> <ion-button fill="clear" color="light" ion-activable class="toast-button" onClick={() => this.dismiss(undefined, 'cancel')}>
{this.closeButtonText || 'Close'} {this.closeButtonText || 'Close'}
</ion-button> </ion-button>
} }