Skip to content

Commit

Permalink
Merge pull request #4007 from ajcrites/reset-scrollview-checkbox-focus
Browse files Browse the repository at this point in the history
fix(scrollView): reset scroll view when focusing non-keyboard element
  • Loading branch information
mlynch committed Dec 6, 2015
2 parents 070b716 + c3faf60 commit c951e1f
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions js/utils/keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ var keyboardLandscapeViewportHeight = 0;
*/
var keyboardActiveElement;

/**
* The previously focused input used to reset keyboard after focusing on a
* new non-keyboard element
*/
var lastKeyboardActiveElement;

/**
* The scroll view containing the currently focused input.
*/
Expand Down Expand Up @@ -311,6 +317,9 @@ function keyboardFocusIn(e) {
e.target.readOnly ||
!ionic.tap.isKeyboardElement(e.target) ||
!(scrollView = ionic.DomUtil.getParentWithClass(e.target, SCROLL_CONTAINER_CSS))) {
if (keyboardActiveElement) {
lastKeyboardActiveElement = keyboardActiveElement;
}
keyboardActiveElement = null;
return;
}
Expand Down Expand Up @@ -546,9 +555,9 @@ function keyboardHide() {
ionic.keyboard.isOpen = false;
ionic.keyboard.isClosing = false;

if (keyboardActiveElement) {
if (keyboardActiveElement || lastKeyboardActiveElement) {
ionic.trigger('resetScrollView', {
target: keyboardActiveElement
target: keyboardActiveElement || lastKeyboardActiveElement
}, true);
}

Expand All @@ -572,6 +581,7 @@ function keyboardHide() {
}

keyboardActiveElement = null;
lastKeyboardActiveElement = null;
}

/**
Expand Down

0 comments on commit c951e1f

Please sign in to comment.