Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Modal focus #2273

Closed
wants to merge 1 commit into from
Closed
Changes from all 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
21 changes: 19 additions & 2 deletions src/modal/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,25 @@ 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 lose focus. This is an issue on touch-
* based devices, which will show and then hide the on-screen keyboard.
* Attempts to refocus the autofocus element via JavaScript will not reopen
* the on-screen keyboard. Fixed by updating the focusing logic to only
* autofocus the modal element if the modal does not contain an autofocus
* element.
*
* Calling focus() on the autofocus element gives it focus if the modal is
* opened more than once.
*/
var autofocusElements = element[0].querySelectorAll('[autofocus]');
if (autofocusElements.length) {
autofocusElements[0].focus();
} else {
element[0].focus();
}
});

scope.close = function (evt) {
Expand Down