ionic-team / cordova-plugin-ionic-keyboard

Keyboard Plugin for Cordova
Other
192 stars 177 forks source link

How to hide keyboard on input focus? #80

Closed templatetuners closed 5 years ago

templatetuners commented 5 years ago

I have an input and I need to focus it to populate with data from a bluetooth barcode scanner. On input:focus() the keyboard is always opening. Tried with Keyboard.hide(); with setTimeout nothing works.

jcesarmobile commented 5 years ago

iOS? Android? both?

Are you using cordova-plugin-ionic-webview?

templatetuners commented 5 years ago

Android Cordova and not using ionic-webview

OMGFoxChen commented 5 years ago

Have you solved it? I have the same problem as you

OMGFoxChen commented 5 years ago

@templatetuners I solved this by setting "readonly".

<ion-input (focus)="handleScanInputFocus()" #scanInput id="scan_input" ></ion-input>

@ViewChild('scanInput') scanInputElement: any;

handleScanInputFocus(){ let elm = this.scanInputElement.getElementRef().nativeElement.firstElementChild;

elm.setAttribute('readonly','readonly'); //The keyboard will not pop up
setTimeout(() => {
  elm.removeAttribute('readonly');  //Remove the "readonly", and the cursor is still in
}, 200)

}

jcesarmobile commented 5 years ago

The keyboard will always appear when you focus it, for preventing it you can do some approaches as the suggested by @OMGFoxChen.

jaronavales commented 2 years ago

How about you have some activity with the page like gestures tap swipe pan, is the cursor still in? @OMGFoxChen

jaronavales commented 2 years ago

@OMGFoxChen you save me <3 Thank you!

DmitryBara commented 1 year ago

You could use inputRef.setBlur() immediately after you focused <IonInput> Then: 1) keyboard will not be appear, 2) input will not be focused 3) but content will be scrolled to that input