fix: keyboard is not displayed on iOS for autofocused inputs - #58760
carlosmiceli merged 2 commits into
Conversation
|
Hey! I see that you made changes to our Form component. Make sure to update the docs in FORMS.md accordingly. Cheers! |
|
@DylanDylann Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
|
Keyboard behavior can vary between iOS and Android, as well as between real devices, simulators, and emulators. For Android system, I was only able to test this on an emulator since I don’t have access to a real Android device. It would be great if someone could run these changes on a physical Android device to verify everything works as expected. Let me know if you notice any issues! |
| const styles = useThemeStyles(); | ||
| const textInputRef = useRef<HTMLFormElement | null>(null); | ||
| const removeVisibilityListenerRef = useRef<RemoveVisibilityListener>(null); | ||
| const isAutoFocusEnabled = typeof ref === 'function' || props.autoFocus; |
There was a problem hiding this comment.
@martasudol Could you help to detail the RCA and how this change will fix the problem?
There was a problem hiding this comment.
The main issue was likely that ref could be a function when using the useAutoFocusInput hook, which might have caused unexpected behavior in the keyboard visibility check.
There was a problem hiding this comment.
But why useAutoFocusInput doesn't work on this case?
There was a problem hiding this comment.
For clear, in useAutoFocusInput we already implemented a logic to auto focus the input
App/src/hooks/useAutoFocusInput.ts
Line 32 in 8c827d7
And I think we need to point out why it doesn't work on the physical devices
There was a problem hiding this comment.
It seems that autofocus is triggered differently on iOS real devices compared to Android or simulators/emulators - timing and visibility behavior can vary quite a bit depending on the platform.
Anyway, I’ve just tested the latest version of the app on a real iOS device, and it looks like the issue is no longer reproducible - everything works as expected now.
Could you please re-test on your side and confirm whether the bug is still happening for you? 🙏 Looks like someone fixed this in the meantime :D
There was a problem hiding this comment.
I still can reproduce on Chrome on Iphone (with latest main)
There was a problem hiding this comment.
You’re right - I was able to reproduce the issue in the browser on iOS as well.
My fix specifically addresses this problem, which only occurs in iOS browsers. The root cause is that React Native for Web doesn’t fully support autofocus for web iOS; a focus trigger is required for autofocus to work properly.
In our case, we use the useAutoFocusInput hook and then pass down the default props, which slightly changes how autofocus is triggered for iOS browsers. This difference in behavior is likely what caused the issue.
Reviewer Checklist
Screenshots/VideosAndroid: NativeScreen.Recording.2025-03-26.at.18.21.17.movAndroid: mWeb ChromeFILE.2025-03-26.16.20.03.mp4iOS: NativeScreen.Recording.2025-03-26.at.18.20.09.moviOS: mWeb Safari6444331329418.mp4MacOS: Chrome / SafariScreen.Recording.2025-03-26.at.18.17.35.movMacOS: DesktopScreen.Recording.2025-03-26.at.18.18.29.mov |
|
We did not find an internal engineer to review this PR, trying to assign a random engineer to #58040 as well as to this PR... Please reach out for help on Slack if no one gets assigned! |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🚀 Deployed to staging by https://github.com/carlosmiceli in version: 9.1.20-0 🚀
|
|
We reverted this PR because it introduced 5 deploy blockers. See here |
|
🚀 Deployed to production by https://github.com/mountiny in version: 9.1.20-2 🚀
|
Explanation of Change
This change fixes the issue of the keyboard not appearing on iOS in the browser (mWeb). The problem occurs not only in the Description Field on the Scan Expense Confirmation Page but also in any input field where we use autofocus.
Fixed Issues
$#58040
Tests
Open the web app on an iOS device (Chrome / Safari).
Navigate to the Create Expense view.
Tap on an input field with autofocus, such as Description or Merchant.
Expected behavior: The keyboard should appear.
Navigate to Settings → Profile → Display Name.
Expected behavior: Input fields should not be auto-focused, and the keyboard should not appear.
Offline tests
Same as Tests.
QA Steps
Same as Tests.
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
https://github.com/user-attachments/assets/71ce1b61-b2c2-48a7-9b97-b419256bd5edAndroid: mWeb Chrome
https://github.com/user-attachments/assets/24aa6d64-7727-4482-b76a-9daddcf0ffb7iOS: Native
https://github.com/user-attachments/assets/0f0ea5b1-cb6f-4d8f-84cb-b108ba023ec3iOS: mWeb Safari
https://github.com/user-attachments/assets/aa30d9e4-439c-4324-abef-8ab5928a921bMacOS: Chrome / Safari
https://github.com/user-attachments/assets/80ae0665-e943-4cec-8a1c-c06d1b78796eMacOS: Desktop
https://github.com/user-attachments/assets/e2d9af49-8f3a-4a27-bc52-effde426a2e2