Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

fix(modal): closing pressed on modal and released out of #6640

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/modal/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 17 additions & 1 deletion src/modal/test/modal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -508,9 +508,12 @@ describe('$uibModal', function() {

it('should support closing on backdrop click', function() {
var modal = open({template: '<div>Content</div>'});
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();
Expand All @@ -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: '<div>Content</div>'});

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 = '<a href>Link</a>';
var element = angular.element(link);
Expand Down