Closed
Description
Ionic version: (check one with "x")
[X] 3.1.1
I'm submitting a ... (check one with "x")
[X] bug report
Current behavior:
Using setFocus() on SearchBar property inside IonViewDidEnter does not set the focus.
Expected behavior:
The focus should be in the searchbar entry area after the page is entered
Steps to reproduce:
- ionic start setFocus blank
- cd setFocus
- update home.html and home.ts as below
- ionic serve
Related code:
home.html
<ion-header>
<ion-navbar>
<ion-title>
Ionic Blank
</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<ion-searchbar #si (ionInput)="onInput($event)"></ion-searchbar>
</ion-content>
home.ts
import { Component, ViewChild } from '@angular/core';
import { Searchbar } from 'ionic-angular';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
@ViewChild('si') searchInput: Searchbar;
constructor() {
}
ionViewDidEnter() {
console.log("setFocus()", this.searchInput);
this.searchInput.setFocus();
}
onInput(ev: any) {
console.log(ev.target.value);
}
}
Other information:
I've only tried this in a browser (Chrome) using ionic serve
Ionic info: (run ionic info
from a terminal/cmd prompt and paste output below):
D:\dev\testSetFocus>ionic info
global packages:
@ionic/cli-utils : 1.0.0-rc.0
Cordova CLI : 6.5.0
Ionic CLI : 3.0.0-rc.0
local packages:
@ionic/app-scripts : 1.3.6
@ionic/cli-plugin-cordova : 1.0.0-rc.0
@ionic/cli-plugin-ionic-angular : 1.0.0-rc.0
Ionic Framework : ionic-angular 3.1.1
System:
Node : v6.10.2
OS : Windows 10
Xcode : not installed
ios-deploy : not installed
ios-sim : not installed