Skip to content

Commit c3faf60

Browse files
committed
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.
1 parent d6431a7 commit c3faf60

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

Diff for: js/utils/keyboard.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ var keyboardLandscapeViewportHeight = 0;
9595
*/
9696
var keyboardActiveElement;
9797

98+
/**
99+
* The previously focused input used to reset keyboard after focusing on a
100+
* new non-keyboard element
101+
*/
102+
var lastKeyboardActiveElement;
103+
98104
/**
99105
* The scroll view containing the currently focused input.
100106
*/
@@ -311,6 +317,9 @@ function keyboardFocusIn(e) {
311317
e.target.readOnly ||
312318
!ionic.tap.isKeyboardElement(e.target) ||
313319
!(scrollView = ionic.DomUtil.getParentWithClass(e.target, SCROLL_CONTAINER_CSS))) {
320+
if (keyboardActiveElement) {
321+
lastKeyboardActiveElement = keyboardActiveElement;
322+
}
314323
keyboardActiveElement = null;
315324
return;
316325
}
@@ -546,9 +555,9 @@ function keyboardHide() {
546555
ionic.keyboard.isOpen = false;
547556
ionic.keyboard.isClosing = false;
548557

549-
if (keyboardActiveElement) {
558+
if (keyboardActiveElement || lastKeyboardActiveElement) {
550559
ionic.trigger('resetScrollView', {
551-
target: keyboardActiveElement
560+
target: keyboardActiveElement || lastKeyboardActiveElement
552561
}, true);
553562
}
554563

@@ -572,6 +581,7 @@ function keyboardHide() {
572581
}
573582

574583
keyboardActiveElement = null;
584+
lastKeyboardActiveElement = null;
575585
}
576586

577587
/**

0 commit comments

Comments
 (0)