Hi guys, how would I make my error text sit on top...
# compose
e
Hi guys, how would I make my error text sit on top of my soft keyboard when there is an error in currently focused text field?
👀 1
s
Copy code
val focusManager = LocalFocusManager.current

var textInput by remember {
    mutableStateOf("")
}

val focusRequester = remember {
    FocusRequester()
}

BasicTextField(
    value = textInput,
    onValueChange = { textInput = it },
    decorationBox = { innerTextField ->
        Column {
            innerTextField()
            if (textInput == "lol") {
                BasicText(text = "no, you can't do that")

                LaunchedEffect(Unit) {
                    focusManager.clearFocus()
                    focusRequester.requestFocus()
                }
            }
        }
    },
    modifier = Modifier
        .focusRequester(focusRequester)
)
Notice the thing you want to get focused must be inside the
decorationBox
and the focus needs to be cleared and request again
âž• 1
e
@ste Thank you so much!
t
I think an alternative is
Modifier.focusGroup
on a Composable containing both the text field and error text
e
@tad Thanks you! I just know that modifier, I'll look into it.