diff --git a/package.json b/package.json index 1eb1866d9d..50c8983bd4 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/src/modal/modal.js b/src/modal/modal.js index 360f87b039..11527341ee 100644 --- a/src/modal/modal.js +++ b/src/modal/modal.js @@ -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){ diff --git a/src/modal/test/modal.spec.js b/src/modal/test/modal.spec.js index e79062ae9f..8f68396db7 100644 --- a/src/modal/test/modal.spec.js +++ b/src/modal/test/modal.spec.js @@ -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: '
' }); + 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: '