Skip to content

Commit

Permalink
fix(action-sheet): allow async button handler returned value
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Sep 20, 2018
1 parent 6b87ead commit 3d3e6a4
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions core/src/components/action-sheet/action-sheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,24 +170,25 @@ export class ActionSheet implements ComponentInterface, OverlayInterface {
return eventMethod(this.el, 'ionActionSheetWillDismiss');
}

private buttonClick(button: ActionSheetButton) {
private async buttonClick(button: ActionSheetButton) {
const role = button.role;
if (isCancel(role)) {
return this.dismiss(undefined, role);
}
const shouldDismiss = this.callButtonHandler(button);
const shouldDismiss = await this.callButtonHandler(button);
if (shouldDismiss) {
return this.dismiss(undefined, button.role);
}
return Promise.resolve();
}

private callButtonHandler(button: ActionSheetButton | undefined): boolean {
private async callButtonHandler(button: ActionSheetButton | undefined) {
if (button && button.handler) {
// a handler has been provided, execute it
// pass the handler the values from the inputs
try {
if (button.handler() === false) {
const rtn = await button.handler();
if (rtn === false) {
// if the return value of the handler is false then do not dismiss
return false;
}
Expand Down

0 comments on commit 3d3e6a4

Please sign in to comment.