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

Commit

Permalink
fix(modal): skipping ESC handling for form inputs
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Allow the user to hit `esc` inside an element in a modal and not exit the modal if the event has been `defaultPrevented`

Closes #3551
Fixes #2544
  • Loading branch information
stryju authored and wesleycho committed Aug 6, 2015
1 parent 1ecd82c commit a05b9c1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
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.3-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
4 changes: 4 additions & 0 deletions src/modal/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,10 @@ angular.module('ui.bootstrap.modal', [])
}

$document.bind('keydown', function (evt) {
if (evt.isDefaultPrevented()) {
return evt;
}

var modal = openedWindows.top();
if (modal && modal.value.keyboard) {
switch (evt.which){
Expand Down
24 changes: 24 additions & 0 deletions src/modal/test/modal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,30 @@ 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').on('keydown', preventKeyDown);

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

expect($document).toHaveModalsOpen(1);

button.off('keydown', preventKeyDown);

triggerKeyDown(button, 27);
$animate.triggerCallbacks();
$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

0 comments on commit a05b9c1

Please sign in to comment.