From e7b273bb197e432db0a7fe799478a2935a148378 Mon Sep 17 00:00:00 2001 From: dpalou Date: Mon, 22 Oct 2018 10:19:45 +0200 Subject: [PATCH] MOBILE-2694 core: Reopen keyboard in Android when show password --- src/components/show-password/show-password.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/components/show-password/show-password.ts b/src/components/show-password/show-password.ts index 7671da8d6..68abdbf70 100644 --- a/src/components/show-password/show-password.ts +++ b/src/components/show-password/show-password.ts @@ -13,7 +13,9 @@ // limitations under the License. import { Component, OnInit, AfterViewInit, Input, ElementRef } from '@angular/core'; +import { CoreDomUtilsProvider } from '@providers/utils/dom'; import { CoreUtilsProvider } from '@providers/utils/utils'; +import { Platform } from 'ionic-angular'; /** * Component to allow showing and hiding a password. The affected input MUST have a name to identify it. @@ -45,7 +47,8 @@ export class CoreShowPasswordComponent implements OnInit, AfterViewInit { protected input: HTMLInputElement; // Input affected. protected element: HTMLElement; // Current element. - constructor(element: ElementRef, private utils: CoreUtilsProvider) { + constructor(element: ElementRef, private utils: CoreUtilsProvider, private domUtils: CoreDomUtilsProvider, + private platform: Platform) { this.element = element.nativeElement; } @@ -106,7 +109,16 @@ export class CoreShowPasswordComponent implements OnInit, AfterViewInit { event.preventDefault(); event.stopPropagation(); + const isFocused = document.activeElement === this.input; + this.shown = !this.shown; this.setData(); + + if (isFocused && this.platform.is('android')) { + // In Android, the keyboard is closed when the input type changes. Focus it again. + setTimeout(() => { + this.domUtils.focusElement(this.input); + }, 400); + } } }