Skip to content

Commit 93aa16a

Browse files
committed
fix(ionicPopup): if input exists, focus it. else, focus first button
Closes #1176
1 parent a33ca26 commit 93aa16a

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

js/angular/service/popup.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ function($animate, $ionicTemplateLoader, $ionicBackdrop, $log, $q, $timeout, $ro
321321
self.element.removeClass('popup-hidden');
322322
self.element.addClass('popup-showing active');
323323
ionic.DomUtil.centerElementByMarginTwice(self.element[0]);
324-
focusLastButton(self.element);
324+
focusInputOrButton(self.element);
325325
});
326326
};
327327
self.hide = function(callback) {
@@ -404,11 +404,14 @@ function($animate, $ionicTemplateLoader, $ionicBackdrop, $log, $q, $timeout, $ro
404404
return resultPromise;
405405
}
406406

407-
function focusLastButton(element) {
408-
var buttons = element[0].querySelectorAll('button');
409-
var lastButton = buttons[buttons.length-1];
410-
if(lastButton) {
411-
lastButton.focus();
407+
function focusInputOrButton(element) {
408+
var inputs = element[0].querySelectorAll('input');
409+
if (!inputs.length) {
410+
inputs = element[0].querySelectorAll('button');
411+
}
412+
var last = inputs[inputs.length-1];
413+
if(last) {
414+
last.focus();
412415
}
413416
}
414417

0 commit comments

Comments
 (0)