fix(modal): skipping ESC handling for form inputs

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
This commit is contained in:
tomasz stryjewski
2015-04-16 10:55:42 +02:00
committed by Wesley Cho
parent 1ecd82ced1
commit a05b9c1ac5
3 changed files with 31 additions and 0 deletions
+3
View File
@@ -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"
+4
View File
@@ -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){
+24
View File
@@ -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>'});