From c3faf60466f8dd308254523cb7998455c1177b81 Mon Sep 17 00:00:00 2001 From: Andrew Crites Date: Mon, 29 Jun 2015 17:53:12 -0400 Subject: [PATCH] fix(scrollView): reset scroll view when focusing non-keyboard element Focusing a keyboard element sets `keyboardActiveElement`. If you blur, this will trigger `resetScrollView` appropriately. If you focus a non-keyboard element, `keyboardActiveElement` is set to null *before* `keyboardHide` is called, so `resetScrollView` is not triggered. Mitigate this by keeping track of the last focused element to reset the scroll view. --- js/utils/keyboard.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/js/utils/keyboard.js b/js/utils/keyboard.js index 9a1655980e6..45417ff46eb 100644 --- a/js/utils/keyboard.js +++ b/js/utils/keyboard.js @@ -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. */ @@ -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; } @@ -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); } @@ -572,6 +581,7 @@ function keyboardHide() { } keyboardActiveElement = null; + lastKeyboardActiveElement = null; } /**