From 70c57beafc74f4fdf8ddc5068db37749e0680016 Mon Sep 17 00:00:00 2001 From: Eddie Lau 3dd13 Date: Fri, 5 Feb 2016 15:47:46 +0800 Subject: [PATCH] add an option to create alert which cannot be dismissed by clicking backdrop --- ionic/components/alert/alert.ts | 20 ++++++++++++-------- ionic/components/alert/test/basic/index.ts | 17 +++++++++++++++++ ionic/components/alert/test/basic/main.html | 3 ++- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/ionic/components/alert/alert.ts b/ionic/components/alert/alert.ts index 51c187476f..edb15c5c47 100644 --- a/ionic/components/alert/alert.ts +++ b/ionic/components/alert/alert.ts @@ -114,7 +114,7 @@ import {ViewController} from '../nav/view-controller'; * } * ``` * - * @demo /docs/v2/demos/alert/ + * @demo /docs/v2/demos/alert/ */ export class Alert extends ViewController { @@ -132,7 +132,8 @@ export class Alert extends ViewController { checked?: boolean, id?: string }>, - buttons?: Array + buttons?: Array, + disableClickBackdropToDismiss?: boolean } = {}) { opts.inputs = opts.inputs || []; opts.buttons = opts.buttons || []; @@ -225,7 +226,8 @@ export class Alert extends ViewController { checked?: boolean, id?: string }>, - buttons?: Array + buttons?: Array, + disableClickBackdropToDismiss?: boolean } = {}) { return new Alert(opts); } @@ -430,12 +432,14 @@ class AlertCmp { } bdClick() { - let cancelBtn = this.d.buttons.find(b => b.role === 'cancel'); - if (cancelBtn) { - this.btnClick(cancelBtn, 1); + if (!this.d.disableClickBackdropToDismiss) { + let cancelBtn = this.d.buttons.find(b => b.role === 'cancel'); + if (cancelBtn) { + this.btnClick(cancelBtn, 1); - } else { - this.dismiss('backdrop'); + } else { + this.dismiss('backdrop'); + } } } diff --git a/ionic/components/alert/test/basic/index.ts b/ionic/components/alert/test/basic/index.ts index cf734e2e21..f986bfe53e 100644 --- a/ionic/components/alert/test/basic/index.ts +++ b/ionic/components/alert/test/basic/index.ts @@ -237,6 +237,23 @@ class E2EPage { }, 100); } + doDisabledBackdropAlert() { + let alert = Alert.create({ + disableClickBackdropToDismiss: true + }); + alert.setTitle('Disabled Backdrop Click'), + alert.setSubTitle('Subtitle'), + alert.setMessage('This is an alert message.'), + alert.addButton({ + text: 'Cancel', + role: 'cancel', + handler: () => { + console.log('Confirm Cancel'); + } + }); + + this.nav.present(alert); + } } diff --git a/ionic/components/alert/test/basic/main.html b/ionic/components/alert/test/basic/main.html index fc742a9cec..505b450b42 100644 --- a/ionic/components/alert/test/basic/main.html +++ b/ionic/components/alert/test/basic/main.html @@ -12,6 +12,7 @@ +
     Confirm Opened: {{testConfirmOpen}}
@@ -24,4 +25,4 @@
     Checkbox Result: {{testCheckboxResult}}
   
- \ No newline at end of file +