I have this TextFied Composable with both KeyboardOptions
and KeyboardActions
.
@Composable
fun TodoInputText(...) {
val keyboardController = LocalSoftwareKeyboardController.current
TextField( ....
onValueChange = onTextChanged,
keyboardOptions = KeyboardOptions.Default.copy(imeAction = ImeAction.Done),
keyboardActions = KeyboardActions(onDone = {
onImeAction()
keyboardController?.hide()
}))}
The TextField is working with the Done Action but I need to disable Done ImeAction on the keyboard whenever the TextFied is empty as illustrated on this GIF
I have already extracted a state to check if the TextField is empty.
@Composable
fun TodoItemEntryInput(...) {
//hold state for TextField
val (text, setText) = remember { mutableStateOf("") }
val isTextBlank = text.isNotBlank()
//declare lambda function submit that handles a submit event when done is pressed
val submitAction = { .... }
TodoItemInput(
text = text,
onTextChange = setText,
submitAction = submitAction,
)}
Now my question is how can I use the isTextBlank
state to disable or Gray-out the Done ImeAction whenever the text is empty. This is to avoid bugs if the user enters blank text - I found input verification not very optimal for this case.