Calling Keyboard.dismiss()
in a button is scrolling to focused input in iOS
#41605
Labels
API: Keyboard
Component: Button
Issue: Author Provided Repro
This issue can be reproduced in Snack or an attached project.
Needs: Triage 🔍
Newer Patch Available
Platform: iOS
iOS applications.
Description
I have a form with several fields (
TextField
) and in the end a button that sends the form data to a server and navigates to another screen if successful.When I'm clicking the button, I dismiss the keyboard and that is causing the last modified input to be focused (it's scrolled into view). Even if I change the button (a
Pressable
) to only callKeyboard.dismiss()
, this issue still happens.From what I tested this only happens if I type characters in the input: if I only tap the input so that it has focus, it works fine; if I only delete some characters it also works fine, that is, the input is not focused (and scrolled to) when I call
Keyboard.dismiss()
.This only happens in iOS (in Android, it works correctly, without scrolling to the input).
It also works if I click in the keyboard "Return" button before clicking the button (it closes the keyboard, but doesn't scroll to the field). If there is a way to trigger it programatically, it could be used as a workaround.
React Native Version
0.72.7
Output of
npx react-native info
Steps to reproduce
Have a form with several
TextField
components and a button at the end. CallKeyboard.dismiss()
in the button. Make it so that when you go to the end of the screen, the first fields are not visible.Type anything in one of the first fields (it can be any field, as long as it's not visible in the end of the screen).
Let the keyboard open, then go to the end of the screen and tap the button (you can also tap outside of any field to close the keyboard).
If you are using iOS, the Textfield is focused (the screen will scroll and focus it).
Snack, screenshot, or link to a repository
https://snack.expo.dev/@lucas99freelas/textfield-keyboard-ios?platform=ios
The text was updated successfully, but these errors were encountered: