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 3 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
4 changes: 4 additions & 0 deletions src/modal/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ angular.module('ui.bootstrap.modal', [])
}

$document.bind('keydown', function (evt) {
if (evt.isPropagationStopped() || /^(?:input|textarea|select)$/i.test(evt.target.nodeName)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, true!
also, forgot to remove the form input check

on it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

went with evt.isDefaultPrevented()

return evt;
}

var modal;

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

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

var input = angular.element( 'input' )
.on( 'keydown', function ( evt ) {
evt.preventDefault();
});

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

expect($document).toHaveModalsOpen(1);

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

expect($document).toHaveModalsOpen(0);
});

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

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