-
Notifications
You must be signed in to change notification settings - Fork 13.5k
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
bug: interactive items in ion-item unexpectedly being focused with delegatesFocus #21982
Comments
Thanks for the issue. Can you reproduce this in a blank Ionic starter app and provide a link to the GitHub repo? |
Thanks for the issue! This issue has been labeled as Please provide a reproduction with the minimum amount of code required to reproduce the issue. Without a reliable code reproduction, it is unlikely we will be able to resolve the issue, leading to it being closed. For a guide on how to create a good reproduction, see our Contributing Guide. |
Here's a full Ionic app which reproduces this issue on Safari in macOS and iOS: https://github.com/larsblumberg/ion-input-focus-stealing-on-safari |
@liamdebeasi If you have any workaround in mind that I could apply, that would be helpful. Due to this issue our iOS app has this awkward behavior that the virtual keyboard opens when the button is tapped (which changes an input value). |
Apologies for the delay. This appears to be related to #22037 (same underlying issue). We have a PR open here: #22049 Though it needs to be updated to address buttons in addition to inputs. The reason this is happening is |
thanks for the update |
I've upgrade this issue's demo app to |
I can reproduce. Looks like we need to account for other focusable elements besides |
@liamdebeasi So this was definitely introduced by ionic-framework/core/src/components/item/item.tsx Lines 180 to 212 in d03807a
That code was added because the input was "kind of" getting focus but not really - the keyboard was opening when the item was pressed but the input didn't have focus. So that just made it so the input actually received the focus it was supposed to have. In my testing of this issue, the input is getting focus only on the first button click, only when the value changes, and only in Safari. This always evaluates to false since the event target is the
Has this been tested with iOS 14? I think it may be another webkit bug with delegatesFocus. Let me know if I'm misunderstanding this! |
On iOS 14.0 the bug still manifests. As well as on MacOS, Safari 14.0 |
To force ion-input to not steal focus,
As a side effect, the ion-button will take on a border when focused.
|
Running Ionic React v5.5.4 and am still seeing this issue with textareas. I have a page with a text input and a text area, and clicking between the two items I see the focus jump back to the textarea. It almost looks like there is a delay in the focus in the textarea |
Running Ionic Angular 5.4.16 and seeing this issue with Edit: I ended up getting around this by adding |
@liamdebeasi any news? thank you! |
Same issue ion Mac / Safari. Due to following structure, clicking anywhere in the content area would snap focus to the input. Also meant user couldn't select and copy text in the content area (and we know that users hate being restricted from using your app in ways you didn't intend...)
Solved this by adding tabindex="0" to the container card:
The only difference for the user is that keyboard tabs now include the whole card on the way to actual inputs. Can't foresee any other issues but happy to be corrected if there are. |
Another workaround is change ion-item to a div with display:flex |
resolves #21982 BREAKING CHANGE: - Item no longer automatically delegates focus to the first focusable element. While most developers should not need to make any changes to account for this update, usages of `ion-item` with interactive elements such as form controls (inputs, textareas, etc) should be evaluated to verify that interactions still work as expected.
Thanks for the issue. This has been resolved via #29091, and a fix will be available in an upcoming major release of Ionic Framework. |
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out. |
Bug Report
Ionic version:
[ ] 4.x
[x] 5.x
Current behavior:
On Safari in macOS or iOS,
IonInput
(ion-input
) steals focus when its value gets changed programmatically.Expected behavior:
ion-input
doesn't take the focus.Steps to reproduce:
The following code snippet reproduces the effect that when an
ion-input
’s value got changed progammatically, here via a button click, then theion-input
will receive focus automatically as an effect. This effect is only observable within anion-item
container.Apart from the fact that this might be unwanted and thus should be controllable by the programmer, it also comes with the side effect of the virtual keyboard popping up since the input receives focus. That’s only acceptable if the user sets focus explicitely on the input. However in this case, the input surprisingly "steals" the focus.
Related code:
Full demo project available here: https://github.com/larsblumberg/ion-input-focus-stealing-on-safari
Other information:
Effect only observable when input is contained within an
ion-item
and only in Safari on macOS and iOS.Ionic info:
The text was updated successfully, but these errors were encountered: