-
Notifications
You must be signed in to change notification settings - Fork 13.5k
V3.1.1 SearchBar setFocus() not setting focus #11453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hello, thanks for opening an issue with us, we will look into this. |
Hey I'm using as a workaround |
Still having this issue? Why is it closed without any comments? |
@simonweber96 @HairyCream desktop or device? |
@manucorporat on desktop it is working perfectly. Even in the Lab serve-environment both Android and iOS are behaving correctly. But when I build the app and run it on the device directly, Android is working, but iOS is not. Weird behaviour ... |
@simonweber96 not that weird. Unfortunately this is likely an unfixable issue. Input.focus() only works if called inside an stack initiated by a touch/mouse/keyboard event. It is known limitation of WK and UIWebView. |
I'm now on Ionic 3.4.0, and it still doesn't work in browser, Android or iOS. |
@HairyCream If it doesn't work in browser, can you make a reproduction plunker/repo? It works for me in browser. On device is a different matter, as manu mentioned. |
@HairyCream , any luck on making that reproduction plunker or repo? |
First, if @manucorporat is correct, and this is a known limitation, then the issue should be re-queued for a documentation update. ... or am I missing something? But, by "browser" I mean the browser session initiated by an ionic serve command. |
OMG, even such a trivial task as setting a "focus" now requires so much effort and nerves. I tried this:
this:
and even this:
nothing works. Is this issue somehow relates to wkwebview? |
@Erbolking This issue relates to iOS's UI/WK web views.
So it is not an issue with ionic. |
@AmitMY thanks One possible solution: |
@HairyCream I've just tested your solution and at least it works for me (Ionic Framework 3.3.0, CLI 2.2.3 and physical device Android 5.1.1). Thanks. |
Any updates on this - is there any hope of a fix or should the issue be closed with a documentation update? I have no problem with the limitation suggested by @manucorporat above but it does not seem to work: I experience the problem if I invoke setFocus() from inside a stack originating from a tap on an item in the auto search results (using wkwebview). Can anybody confirm they have observed this working or was it just an assumption that it would work? I have applied the suggested patch to no avail. I have tried the setTimeout suggestion, also to no avail (I don't understand how the latter suggestion could work as it contradicts the requirement that the event must originate from a touch/mouse/keyboard event?). Any status update on the issue as well as new ideas or suggestions are very welcome! |
I figured this out the brutal way. The problem isn't a deadlock. I had to invite KEYBOARD plugin into the picture as though i wanted to reinvent the wheels:
Code
|
@chukwu Thanks for sharing! I ended up doing the below, which worked out great for me. What device did you test this on? I was curious why the 2000ms on the setTimeout? Just to be on the safe side or did you have issues on slower devices?
|
@keithdmoore .... The delayed timeout doesn't make much of a difference. Just make sure device/plugin is ready and view is loaded. |
I'd like to add a suggestion to everyone that is going through this issue either now or will stumble on it in the future. I'd suggest logging your searchbar viewchild before setting focus on it. If it comes back as undefined, that probably means your setFocus() is being called before ionic searchbar has initialized. This could happen because of *ngIf because the element is not initialized until it passes the conditional flag and could cause delay in between creation and using one of its function. In that case, use a small timeout (150ms) and then log it again. If you do see it, then set the focus within that timeout. |
@anjildhamala I found that I didn't need to use the onKeyboardShow event listener. I just needed the timeout. |
I have the same problem on Chrome on Windows desktop. |
i made the focus work with a bigger timeout and had to add the show method on the keyboard (tested only on android). ionic 2 and 3 Code:
|
Is there a reason why the setFocus documentation hasn't been updated yet? |
after reading too many threads, i have tried below code and it is working fine for iOS.
For iOS, if someone want to show cancel button always then you can add below css,
So basically , to setFocus work on iOS , you need to setFocus in viewDidEnter instead of iosViewWillEnter/ionViewDidLoad.
|
@SaurabhPrajapati does setfocus inside ngzone open the keyboard on ios? |
This issue has been automatically identified as an Ionic 3 issue. We recently moved Ionic 3 to its own repository. I am moving this issue to the repository for Ionic 3. Please track this issue over there. If I've made a mistake, and if this issue is still relevant to Ionic 4, please let the Ionic Framework team know! Thank you for using Ionic! |
Issue moved to: ionic-team/ionic-v3#280 |
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:
Related code:
home.html
home.ts
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):The text was updated successfully, but these errors were encountered: