diff --git a/src/modal/modal.js b/src/modal/modal.js index 317f36737d..a66ba551b5 100644 --- a/src/modal/modal.js +++ b/src/modal/modal.js @@ -95,7 +95,7 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.transition']) // trigger CSS transitions scope.animate = true; // focus a freshly-opened modal - element[0].focus(); + (element.find('*[autofocus]')[0] || element[0]).focus(); }); scope.close = function (evt) { diff --git a/src/modal/test/modal.spec.js b/src/modal/test/modal.spec.js index d3424c06ed..2127a8858b 100644 --- a/src/modal/test/modal.spec.js +++ b/src/modal/test/modal.spec.js @@ -118,6 +118,10 @@ describe('$modal', function () { $rootScope.$digest(); } + function isFocused(elm) { + return elm[0] === document.activeElement; + } + describe('basic scenarios with default options', function () { it('should open and dismiss a modal with a minimal set of options', function () { @@ -183,6 +187,18 @@ describe('$modal', function () { expect($document).not.toHaveBackdrop(); }); + it('should focus on autofocus element', function () { + var modal = open({template: '