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:
committed by
Wesley Cho
parent
1ecd82ced1
commit
a05b9c1ac5
@@ -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"
|
||||
|
||||
@@ -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){
|
||||
|
||||
@@ -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>'});
|
||||
|
||||
Reference in New Issue
Block a user