In that post you set a local variable (#input) and then use that variable in your code to set the focus. With the searchbar being generated how would I assign a local variable to it? In my case I have the searchbar hidden until a search button in the navbar is pressed, at that point I unhide the searchbar and would like to set focus and open the keyboard at the same time.
Currently the ion-searchbar does not have a method to set focus built it.
Something like this could be added though, would you be able to open an issue for it?
In my case I have the searchbar hidden until a search button in the navbar is pressed
After using @chrisbenseler solution I had to add a timeout of about 50ms on the setFocus to get the DOM to load after un-hiding the searchbar element. Just FYI
Worked for me using the below. Any less than 600 and it doesn’t work for me.
I’m not reloading the page so I don’t really understand why I need to do this. In a web app I can just keep the focus in an input and search on each keypress. This feels like a hack.
Ok I realised it was because I was using a LoadingController that I was losing focus on the SearchBar. I removed this and added a spinner to my list and problem resolved. No need to use setFocus in this case.