From 420aa6639214e7d2e7b7413e699ace3d7fd35e40 Mon Sep 17 00:00:00 2001 From: Liam DeBeasi Date: Wed, 30 Oct 2019 14:02:18 -0400 Subject: [PATCH] fix(toast): call button handler on cancel (#19793) fixes #19791 --- core/src/components/toast/toast.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/core/src/components/toast/toast.tsx b/core/src/components/toast/toast.tsx index cd15330b32..0abf142385 100644 --- a/core/src/components/toast/toast.tsx +++ b/core/src/components/toast/toast.tsx @@ -191,7 +191,7 @@ export class Toast implements ComponentInterface, OverlayInterface { } const shouldDismiss = await this.callButtonHandler(button); if (shouldDismiss) { - return this.dismiss(undefined, button.role); + return this.dismiss(undefined, role); } return Promise.resolve(); } @@ -213,6 +213,14 @@ export class Toast implements ComponentInterface, OverlayInterface { return true; } + private dispatchCancelHandler = (ev: CustomEvent) => { + const role = ev.detail.role; + if (isCancel(role)) { + const cancelButton = this.getButtons().find(b => b.role === 'cancel'); + this.callButtonHandler(cancelButton); + } + } + renderButtons(buttons: ToastButton[], side: 'start' | 'end') { if (buttons.length === 0) { return; @@ -265,6 +273,7 @@ export class Toast implements ComponentInterface, OverlayInterface { ...getClassMap(this.cssClass), 'toast-translucent': this.translucent }} + onIonToastWillDismiss={this.dispatchCancelHandler} >