Key board cannot set focus when startup the app

  • I cannot setFocus() by the code like, my code

    ionViewDidEnter() {

      // Set timeout wait keyboard ready
         setTimeout(() => {
             this.myInput.setFocus();
         }, 20000);

}
I also add this to the config.xml: preference name=“KeyboardDisplayRequiresUserAction” value=“false” \

I used isFocus() to check the status , it always return false. This problem only on android 9 device, on some old devices, it worked normally.
(My case: Open the app, open keyboard automatically.)

After test and take a lot of time for it . I figured out that i have to click once time at the start up time to screen. After that it work perfectly (i can set focus to the input and open keyboard automatically).

I don’t know why? Anyone know this problem? Please help me. Why we have to click once time to the screen to make it work? Can we don’t need to do that?

you could use autofocus property on input field, here is the demo:

<ion-input type="text" autofocus"true"></ion-input>

I tried. But it’s not working.

I opened keyboard by native key board plugin. i can click on keyboard. But the input not change, still not focus.

I have the same issue. Put focus in a HTML element with Ionic is a nightmare…

I use a modal to “push” a page but the keyboard and focus is lost after 1,2 seconds

let modal = this.modalCtrl.create(AddlineaPage);
modal.onDidDismiss(data => {
this.calculaTotales();
});
modal.present({
keyboardClose: false
});

<input id=“codigoArticulo” [(ngModel)]=“codigoArticulo” value="{{ this.codarticulo }}" type=“number” class=“campo” autofocus/>

The keyboard and focus is lost after 1,2 seconds after load.

I have seen several solutions and 0 worked.

Is there any standard to avoid this problem?

I only faced this problem the first time When start up the app. I also have the page which use push a “modal” then open the keyboard, it 's work perfectly. Have you tried increasing timeout in ionViewDidLoad

  setTimeout(() => {
             this.myInput.setFocus();
  }, 1000);
1 Like

Oh c’mon, that’s helped me very much… That “fixed” my problem but i don’t know why we have to wait to focus an element when the page is loaded…

Sorry to “pollute” ur post with my problems

Finally. I decided create my own keyboard with Modal, Css, Html. Didn’t use the plugin keyboard,

1 Like