Is there some way to make a `TextField` unfocus? I...
# compose
f
Is there some way to make a
TextField
unfocus? I can't draw focus away not by tapping outside, or by tapping the IME action on the keyboard, and I can't find a way to do it in code (something like a FocusNode I get from the
TextField
that I can call
unfocus()
on) I've found some outdated discussion about it: https://kotlinlang.slack.com/archives/CJLTWPH7S/p1584069025456900?thread_ts=1584053267.453300&cid=CJLTWPH7S
👍 1
s
@Ralston Da Silva I forgot how we do it now
m
+1 to this, im also keen to know how to get get focus off a textfield or hide the keyboard from an ime action.
r
Sorry, we haven't added an API to do that yet. I filed a bug to make sure I add it: https://issuetracker.google.com/issues/161487952
For now, here is a workaround:
Copy code
@Composable
fun Sample() {
    var text by savedInstanceState { "" }
    val hostView = ViewAmbient.current
    Row(modifier = Modifier.tapGestureFilter { hostView.clearFocus() }) {
        TextField(value = text,
            onValueChange = { text = it },
            label = { Text("Enter Text Here") }
        )
    }
}