diff --git a/src/modal/modal.js b/src/modal/modal.js index 679ff188e8..b0035541e2 100644 --- a/src/modal/modal.js +++ b/src/modal/modal.js @@ -101,7 +101,13 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.multiMap', 'ui.bootstrap.sta }; // moved from template to fix issue #2280 - element.on('click', scope.close); + element.on('mousedown', function(evt1) { + element.one('mouseup', function(evt2) { + if (evt1.target === evt2.target) { + scope.close.apply(this, arguments); + } + }); + }); // This property is only added to the scope for the purpose of detecting when this directive is rendered. // We can detect that by using this property in the template associated with this directive and then use diff --git a/src/modal/test/modal.spec.js b/src/modal/test/modal.spec.js index 4bf85243da..5bc55bb85b 100644 --- a/src/modal/test/modal.spec.js +++ b/src/modal/test/modal.spec.js @@ -508,9 +508,12 @@ describe('$uibModal', function() { it('should support closing on backdrop click', function() { var modal = open({template: '
Content
'}); + var selector = 'body > div.modal'; expect($document).toHaveModalsOpen(1); - $document.find('body > div.modal').click(); + $document.find(selector).mousedown(); + $document.find(selector).mouseup(); + $animate.flush(); $rootScope.$digest(); $animate.flush(); @@ -519,6 +522,19 @@ describe('$uibModal', function() { expect($document).toHaveModalsOpen(0); }); + it('should not close modal when initial click was on slider and mouseup on backdrop', function() { + var selector = 'div.modal-dialog'; + open({template: '
Content
'}); + + expect($document).toHaveModalsOpen(1); + + $document.find(selector).mousedown(); + $document.find('body > div.modal').mouseup(); + $document.find(selector).click(); + + expect($document).toHaveModalsOpen(1); + }); + it('should return to the element which had focus before the dialog was invoked', function() { var link = 'Link'; var element = angular.element(link);