So when I toggle to search bar by clicking on search icon for first time search bar get focus but alphabetic keyboard comes up, I want number keyboard to come up. If I remove this.keyboard.show(); from directive code, then for first time no keyboard comes up. I don’t have this problem with successive clicks. Can anybody help me in this?
HTML Code
<ion-searchbar class="searchBarPadding" focuserSingle
placeholder="Search"
(change)="toggleSearchBar()" [(ngModel)]="input" type="number"
(ionBlur)="toggleSearchBar()"> </ion-searchbar>
Focus Directive I am using
import { Directive, Renderer, ElementRef } from '@angular/core';
import { Keyboard } from '@ionic-native/keyboard';
@Directive({
selector: '[focuser]' // Attribute selector
})
export class FocuserDirective {
constructor(private renderer: Renderer,
private elementRef: ElementRef,
private keyboard:Keyboard) {
}
ngAfterViewInit() {
const element = this.elementRef.nativeElement.querySelector('input');
setTimeout(() => {
this.renderer.invokeElementMethod(element, 'focus', []);
this.keyboard.show();
}, 0);
}
}