How to catch leave event from OutlinedTextField to close keyboard?
fun LabelName(nameUpdate: String = "", name: (String) -> Unit) {
OutlinedTextField(
modifier = Modifier
.fillMaxWidth()
.padding(end = 20.dp),
value = nameUpdate,
onValueChange = {
name(manageLength(it))
},
label = {
Text(text = stringResource(id = if ( nameUpdate.isNotEmpty() ) R.string.name else R.string.add_new_name))
}
}
But then I click on the button, OutlinedTextField stayed focusable
If you only want to hide the keyboard then use
keyboardControlleronly. I also recommend changing the keyboard button to done, as I did in the example below. And if you want to turn off the focus, you need to addLocalFocusManagerso that after pressing the done button on the keyboard on the phone, the focus will be immediately set toOutlinedTextField.