Skip to content

Commit

Permalink
feat(alert): disable clicking backdrop to dismiss
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Feb 5, 2016
1 parent b08794e commit 53e014f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
14 changes: 7 additions & 7 deletions ionic/components/alert/alert.ts
Expand Up @@ -133,10 +133,11 @@ export class Alert extends ViewController {
id?: string
}>,
buttons?: Array<any>,
disableClickBackdropToDismiss?: boolean
enableBackdropDismiss?: boolean
} = {}) {
opts.inputs = opts.inputs || [];
opts.buttons = opts.buttons || [];
opts.enableBackdropDismiss = (opts.enableBackdropDismiss === false ? false : true);

super(AlertCmp, opts);
this.viewType = 'alert';
Expand Down Expand Up @@ -227,7 +228,7 @@ export class Alert extends ViewController {
id?: string
}>,
buttons?: Array<any>,
disableClickBackdropToDismiss?: boolean
enableBackdropDismiss?: boolean
} = {}) {
return new Alert(opts);
}
Expand Down Expand Up @@ -373,13 +374,12 @@ class AlertCmp {
let self = this;
self.keyUp = function(ev) {
if (ev.keyCode === 13) {
// enter
console.debug('alert enter');
console.debug('alert, enter button');
let button = self.d.buttons[self.d.buttons.length - 1];
self.btnClick(button);

} else if (ev.keyCode === 27) {
console.debug('alert escape');
console.debug('alert, escape button');
self.bdClick();
}
};
Expand Down Expand Up @@ -432,7 +432,7 @@ class AlertCmp {
}

bdClick() {
if (!this.d.disableClickBackdropToDismiss) {
if (this.d.enableBackdropDismiss) {
let cancelBtn = this.d.buttons.find(b => b.role === 'cancel');
if (cancelBtn) {
this.btnClick(cancelBtn, 1);
Expand Down Expand Up @@ -470,7 +470,7 @@ class AlertCmp {
return values;
}

onPageDidLeave() {
onPageWillLeave() {
document.removeEventListener('keyup', this.keyUp);
}
}
Expand Down
5 changes: 2 additions & 3 deletions ionic/components/alert/test/basic/index.ts
Expand Up @@ -239,11 +239,10 @@ class E2EPage {

doDisabledBackdropAlert() {
let alert = Alert.create({
disableClickBackdropToDismiss: true
enableBackdropDismiss: false
});
alert.setTitle('Disabled Backdrop Click'),
alert.setSubTitle('Subtitle'),
alert.setMessage('This is an alert message.'),
alert.setMessage('Cannot dismiss alert from clickings the backdrop'),
alert.addButton({
text: 'Cancel',
role: 'cancel',
Expand Down

0 comments on commit 53e014f

Please sign in to comment.