From b60358583accc6225c4b35ddaa460669b4295320 Mon Sep 17 00:00:00 2001 From: Sergey Zolotarev Date: Tue, 31 Jan 2017 14:47:22 +0600 Subject: [PATCH] Don't add keyboard-open to CSS if keyboard is already hidden The 'keyboard-open' CSS class is added to body after a 400ms delay, but nothing stops somebody from hiding the keyboard during this short period of time, for example by tapping on empty space. So we need to kill the timer responsible for adding this class when the keyboard hides. See this comment for some more details: https://github.com/driftyco/ionic/issues/3041#issuecomment-276296886 --- js/utils/keyboard.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/js/utils/keyboard.js b/js/utils/keyboard.js index 45417ff46..56ff3e53d 100644 --- a/js/utils/keyboard.js +++ b/js/utils/keyboard.js @@ -132,6 +132,11 @@ var wasOrientationChange = false; */ var KEYBOARD_OPEN_CSS = 'keyboard-open'; +/** + * Timer that adds KEYBOARD_OPEN_CSS class to the body. + */ +var keyboardOpenCssTimer; + /** * CSS class that indicates a scroll container. */ @@ -550,6 +555,7 @@ function keyboardWaitForResize(callback, isOpening) { */ function keyboardHide() { clearTimeout(keyboardFocusOutTimer); + clearTimeout(keyboardOpenCssTimer); //console.log("keyboardHide"); ionic.keyboard.isOpen = false; @@ -621,7 +627,7 @@ function keyboardShow() { ionic.trigger('scrollChildIntoView', details, true); } - setTimeout(function(){ + keyboardOpenCssTimer = setTimeout(function() { document.body.classList.add(KEYBOARD_OPEN_CSS); }, 400);