Skip to content

Commit 291d723

Browse files
committed
feat($ionicModal): allow configuration of backdropClickToClose
Addresses #1087
1 parent 3806482 commit 291d723

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

Diff for: js/angular/service/modal.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
* $scope.$on('$destroy', function() {
3939
* $scope.modal.remove();
4040
* });
41-
* // Execute action on hide modal
41+
* // Execute action on hide modal
4242
* $scope.$on('modal.hide', function() {
4343
* // Execute action
4444
* });
@@ -85,6 +85,8 @@ function($rootScope, $document, $compile, $timeout, $ionicPlatform, $ionicTempla
8585
* Default: 'slide-in-up'
8686
* - `{boolean=}` `focusFirstInput` Whether to autofocus the first input of
8787
* the modal when shown. Default: false.
88+
* - `{boolean=} `backdropClickToClose` Whether to close the modal on clicking the backdrop.
89+
* Default: true.
8890
*/
8991
initialize: function(opts) {
9092
ionic.views.Modal.prototype.initialize.call(this, opts);
@@ -132,7 +134,7 @@ function($rootScope, $document, $compile, $timeout, $ionicPlatform, $ionicTempla
132134
return $timeout(function() {
133135
//After animating in, allow hide on backdrop click
134136
self.$el.on('click', function(e) {
135-
if (e.target === self.el) {
137+
if (self.backdropClickToClose && e.target === self.el) {
136138
self.hide();
137139
}
138140
});

Diff for: js/views/modalView.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
opts = ionic.extend({
77
focusFirstInput: false,
88
unfocusOnHide: true,
9-
focusFirstDelay: 600
9+
focusFirstDelay: 600,
10+
backdropClickToClose: true,
1011
}, opts);
1112

1213
ionic.extend(this, opts);

Diff for: test/unit/angular/service/modal.unit.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,17 @@ describe('Ionic Modal', function() {
111111
expect(instance.hide).toHaveBeenCalled();
112112
});
113113

114-
it('should close modal on backdrop click if target is not backdrop', function() {
114+
it('should not close modal on backdrop click if options.backdropClickToClose', function() {
115+
var template = '<div class="modal"></div>';
116+
var instance = modal.fromTemplate(template, { backdropClickToClose: false });
117+
spyOn(instance, 'hide');
118+
instance.show();
119+
timeout.flush();
120+
instance.$el.triggerHandler('click');
121+
expect(instance.hide).not.toHaveBeenCalled();
122+
});
123+
124+
it('should not close modal on backdrop click if target is not backdrop', function() {
115125
var template = '<div class="modal"></div>';
116126
var instance = modal.fromTemplate(template);
117127
spyOn(instance, 'hide');

0 commit comments

Comments
 (0)