Skip to content

Commit

Permalink
fix(modal): respect autofocus on child elements
Browse files Browse the repository at this point in the history
Auto-focusing of a freshly-opened modal element causes any child
elements with the autofocus attribute to loose focus. This is an issue
on touch based devices which will show and then hide the onscreen
keyboard. Attempts to refocus the autofocus element via JavaScript will
not reopen the onscreen keyboard. Fixed by updated the focusing logic to
only autofocus the modal element if the modal does not contain an
autofocus element.

Fixes angular-ui#1696
Closes angular-ui#1892
Closes angular-ui#2273
  • Loading branch information
mlilli authored and jurassic-c committed Aug 6, 2014
1 parent 04951f7 commit c361f52
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/modal/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,18 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.transition'])
$timeout(function () {
// trigger CSS transitions
scope.animate = true;
// focus a freshly-opened modal
element[0].focus();

/**
* Auto-focusing of a freshly-opened modal element causes any child elements
* with the autofocus attribute to loose focus. This is an issue on touch
* based devices which will show and then hide the onscreen keyboard.
* Attempts to refocus the autofocus element via JavaScript will not reopen
* the onscreen keyboard. Fixed by updated the focusing logic to only autofocus
* the modal element if the modal does not contain an autofocus element.
*/
if (!element[0].querySelectorAll('[autofocus]').length) {
element[0].focus();
}
});

scope.close = function (evt) {
Expand Down

0 comments on commit c361f52

Please sign in to comment.