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

fix(modal): skipping ESC handling for form inputs; fixes #2544 #3551

Closed
wants to merge 4 commits into from
Closed
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
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"version": "0.13.0-SNAPSHOT",
"homepage": "http://angular-ui.github.io/bootstrap/",
"dependencies": {},
"scripts":{
"test": "grunt"
},
"repository": {
"type": "git",
"url": "https://github.com/angular-ui/bootstrap.git"
Expand Down
5 changes: 5 additions & 0 deletions src/modal/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,11 @@ angular.module('ui.bootstrap.modal', [])
}

$document.bind('keydown', function (evt) {

if (evt.isDefaultPrevented()) {
return evt;
}

var modal;

if (evt.which === 27) {
Expand Down
26 changes: 26 additions & 0 deletions src/modal/test/modal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,32 @@ describe('$modal', function () {
expect($document).toHaveModalsOpen(0);
});

it('should not close on ESC if event.preventDefault() was issued', function () {
var modal = open({template: '<div><button>x</button></div>' });
expect($document).toHaveModalsOpen(1);

var button = angular.element('button').bind('keydown', preventKeyDown);

triggerKeyDown(button, 27);
$timeout.flush();
$rootScope.$digest();

expect($document).toHaveModalsOpen(1);

button.unbind('keydown', preventKeyDown);

triggerKeyDown(button, 27);
$timeout.flush();
$rootScope.$digest();

expect($document).toHaveModalsOpen(0);


function preventKeyDown(evt) {
evt.preventDefault();
}
});

it('should support closing on backdrop click', function () {

var modal = open({template: '<div>Content</div>'});
Expand Down