Skip to content

Commit

Permalink
fix(ionicPopup): if input exists, focus it. else, focus first button
Browse files Browse the repository at this point in the history
Closes #1176
  • Loading branch information
ajoslin committed Apr 21, 2014
1 parent a33ca26 commit 93aa16a
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions js/angular/service/popup.js
Expand Up @@ -321,7 +321,7 @@ function($animate, $ionicTemplateLoader, $ionicBackdrop, $log, $q, $timeout, $ro
self.element.removeClass('popup-hidden');
self.element.addClass('popup-showing active');
ionic.DomUtil.centerElementByMarginTwice(self.element[0]);
focusLastButton(self.element);
focusInputOrButton(self.element);
});
};
self.hide = function(callback) {
Expand Down Expand Up @@ -404,11 +404,14 @@ function($animate, $ionicTemplateLoader, $ionicBackdrop, $log, $q, $timeout, $ro
return resultPromise;
}

function focusLastButton(element) {
var buttons = element[0].querySelectorAll('button');
var lastButton = buttons[buttons.length-1];
if(lastButton) {
lastButton.focus();
function focusInputOrButton(element) {
var inputs = element[0].querySelectorAll('input');
if (!inputs.length) {
inputs = element[0].querySelectorAll('button');
}
var last = inputs[inputs.length-1];
if(last) {
last.focus();
}
}

Expand Down

0 comments on commit 93aa16a

Please sign in to comment.