Skip to content

Commit 53e014f

Browse files
committed
feat(alert): disable clicking backdrop to dismiss
1 parent b08794e commit 53e014f

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

ionic/components/alert/alert.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,11 @@ export class Alert extends ViewController {
133133
id?: string
134134
}>,
135135
buttons?: Array<any>,
136-
disableClickBackdropToDismiss?: boolean
136+
enableBackdropDismiss?: boolean
137137
} = {}) {
138138
opts.inputs = opts.inputs || [];
139139
opts.buttons = opts.buttons || [];
140+
opts.enableBackdropDismiss = (opts.enableBackdropDismiss === false ? false : true);
140141

141142
super(AlertCmp, opts);
142143
this.viewType = 'alert';
@@ -227,7 +228,7 @@ export class Alert extends ViewController {
227228
id?: string
228229
}>,
229230
buttons?: Array<any>,
230-
disableClickBackdropToDismiss?: boolean
231+
enableBackdropDismiss?: boolean
231232
} = {}) {
232233
return new Alert(opts);
233234
}
@@ -373,13 +374,12 @@ class AlertCmp {
373374
let self = this;
374375
self.keyUp = function(ev) {
375376
if (ev.keyCode === 13) {
376-
// enter
377-
console.debug('alert enter');
377+
console.debug('alert, enter button');
378378
let button = self.d.buttons[self.d.buttons.length - 1];
379379
self.btnClick(button);
380380

381381
} else if (ev.keyCode === 27) {
382-
console.debug('alert escape');
382+
console.debug('alert, escape button');
383383
self.bdClick();
384384
}
385385
};
@@ -432,7 +432,7 @@ class AlertCmp {
432432
}
433433

434434
bdClick() {
435-
if (!this.d.disableClickBackdropToDismiss) {
435+
if (this.d.enableBackdropDismiss) {
436436
let cancelBtn = this.d.buttons.find(b => b.role === 'cancel');
437437
if (cancelBtn) {
438438
this.btnClick(cancelBtn, 1);
@@ -470,7 +470,7 @@ class AlertCmp {
470470
return values;
471471
}
472472

473-
onPageDidLeave() {
473+
onPageWillLeave() {
474474
document.removeEventListener('keyup', this.keyUp);
475475
}
476476
}

ionic/components/alert/test/basic/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,10 @@ class E2EPage {
239239

240240
doDisabledBackdropAlert() {
241241
let alert = Alert.create({
242-
disableClickBackdropToDismiss: true
242+
enableBackdropDismiss: false
243243
});
244244
alert.setTitle('Disabled Backdrop Click'),
245-
alert.setSubTitle('Subtitle'),
246-
alert.setMessage('This is an alert message.'),
245+
alert.setMessage('Cannot dismiss alert from clickings the backdrop'),
247246
alert.addButton({
248247
text: 'Cancel',
249248
role: 'cancel',

0 commit comments

Comments
 (0)