diff --git a/src/modal/modal.js b/src/modal/modal.js index 7bcf36f098..18b9f53d9c 100644 --- a/src/modal/modal.js +++ b/src/modal/modal.js @@ -351,13 +351,15 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap']) } var modal = openedWindows.top(); - if (modal && modal.value.keyboard) { + if (modal) { switch (evt.which) { case 27: { - evt.preventDefault(); - $rootScope.$apply(function() { - $modalStack.dismiss(modal.key, 'escape key press'); - }); + if (modal.value.keyboard) { + evt.preventDefault(); + $rootScope.$apply(function() { + $modalStack.dismiss(modal.key, 'escape key press'); + }); + } break; } case 9: { diff --git a/src/modal/test/modal.spec.js b/src/modal/test/modal.spec.js index 413741fcf0..f5410202e6 100644 --- a/src/modal/test/modal.spec.js +++ b/src/modal/test/modal.spec.js @@ -527,6 +527,46 @@ describe('$uibModal', function () { initialPage.remove(); }); + + it('should change focus to first element when tab key was pressed even if keyboard=false options is provided', function() { + var initialPage = angular.element('Outland link'); + angular.element(document.body).append(initialPage); + initialPage.focus(); + + open({ + template:'' + + '', + keyboard: false + }); + expect($document).toHaveModalsOpen(1); + + var lastElement = angular.element(document.getElementById('tab-focus-button')); + lastElement.focus(); + triggerKeyDown(lastElement, 9); + expect(document.activeElement.getAttribute('id')).toBe('tab-focus-link'); + + initialPage.remove(); + }); + + it('should change focus to last element when shift+tab key is pressed even if keyboard=false options is provided', function() { + var initialPage = angular.element('Outland link'); + angular.element(document.body).append(initialPage); + initialPage.focus(); + + open({ + template:'' + + '', + keyboard: false + }); + expect($document).toHaveModalsOpen(1); + + var lastElement = angular.element(document.getElementById('tab-focus-link')); + lastElement.focus(); + triggerKeyDown(lastElement, 9, true); + expect(document.activeElement.getAttribute('id')).toBe('tab-focus-button'); + + initialPage.remove(); + }); }); describe('default options can be changed in a provider', function() {