From f7f247dc67c3e01826af4df1523f5c6261749dd2 Mon Sep 17 00:00:00 2001 From: sergey-zhernosek Date: Wed, 27 Sep 2017 11:31:22 +0300 Subject: [PATCH 1/2] fix: modal closing bug --- src/modal/modal.js | 8 +++++++- src/modal/test/modal.spec.js | 18 +++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) 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..bde9f32c87 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 = 'body > div.modal'; + open({template: '
Content
'}); + + expect($document).toHaveModalsOpen(1); + + $document.find('div.modal-dialog').mousedown(); + $document.find(selector).mouseup(); + $document.find('div.modal-dialog').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); From 512890fdcc100e072c942d323fe1a79a8c94f7aa Mon Sep 17 00:00:00 2001 From: sergey-zhernosek Date: Wed, 27 Sep 2017 12:17:32 +0300 Subject: [PATCH 2/2] fix(modal): refactor test --- src/modal/test/modal.spec.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/modal/test/modal.spec.js b/src/modal/test/modal.spec.js index bde9f32c87..5bc55bb85b 100644 --- a/src/modal/test/modal.spec.js +++ b/src/modal/test/modal.spec.js @@ -523,14 +523,14 @@ describe('$uibModal', function() { }); it('should not close modal when initial click was on slider and mouseup on backdrop', function() { - var selector = 'body > div.modal'; + var selector = 'div.modal-dialog'; open({template: '
Content
'}); expect($document).toHaveModalsOpen(1); - $document.find('div.modal-dialog').mousedown(); - $document.find(selector).mouseup(); - $document.find('div.modal-dialog').click(); + $document.find(selector).mousedown(); + $document.find('body > div.modal').mouseup(); + $document.find(selector).click(); expect($document).toHaveModalsOpen(1); });