When a user taps on the submit button the app focuses on that TextField
if there is an error with input data, it works fine but it automatically opens the keyboard which is shown below TextField
and covers Text
error which is placed below TextField
and user needs to close the keyboard first before he can the what is the problem.
val focusRequester = remember { FocusRequester() }
val shouldFocusOnError = textFieldState.shouldFocusOnError // mutable state field
LaunchedEffect(shouldFocusOnError) {
if (shouldFocusOnError) {
focusRequester.requestFocus()
textFieldState.shouldFocusOnError = false
}
}
TextField(
modifier = Modifier.fillMaxWidth()
.focusRequester(focusRequester)
...
)
val errorText = textFieldState.errorText
if (!errorText.isNullOrEmpty()) {
Text(
text = errorText,
...
)
}
So basically I just need to move to this TextField
(in case there is scroll and long column so user could see the error)
Updated
Actually I can use supportingText = {}
field instead to show errors, in this case the keyboard is showing below this supportingText.
But still would be great to know how to focus to the textfield without showing the keyboard