ion-searchbar autofocus
See original GitHub issueFeature Request
Ionic version:
[x] 4.x
Describe the Feature Request
Add support for autofocus
property to ionic core for feature parity with ion-input
. Previous patch for v3
in https://github.com/ionic-team/ionic/pull/8232 but probably outdated.
Describe Preferred Solution
Boolean property for ion-searchbar
will do.
<ion-searchbar autofocus></ion-searchbar>
Describe Alternatives
The alternative uses a simple timeout (don’t follow this, not tested) based on angular.
<ion-seachbar #autofocus></ion-searchbar>
@Component(...)
export class SimpleSearch implements OnInit {
@ViewContent('#autofocus') searchbar;
ngOnInit() {
setTimeout(() => this.searchbar.focus(), 300);
}
}
Related Code
Additional Context
Issue Analytics
- State:
- Created 5 years ago
- Reactions:8
- Comments:10 (2 by maintainers)
Top Results From Across the Web
Autofocus on ion-searchbar - Ionic Forum
There is not autofocus ability for ion-searchbar. Have looked into it quite a bit, we decided that autofocus was too problematic. Working across ......
Read more >How to focus ion-searchbar on button click - Stack Overflow
I am trying to focus ion-searchbar on button click but it is not working. This is my code. Typescript @ViewChild('search') search:ElementRef ...
Read more >Ionic Searchbar Setfocus - StackBlitz
Starter project for Ionic apps that exports to the Ionic CLI.
Read more >How to add and set ionic autofocus input - Edupala
In your template add ion-searchbar tag or any input tag with #autofocus as a local variable, this variable can be used in our...
Read more >Auto-focus Input and Open Keypad On View/ Page Load in ...
In Ionic application too we can achieve this behavior by 2 simple steps, the best thing is we don't need any plugin for...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@ViewChild(IonSearchbar) myInput: IonSearchbar;
setTimeout(() => { this.myInput.setFocus(); }, 150);
import { IonSearchbar} from '@ionic/angular';
Without setTimeout