Is there a way for TextField to update a `MutableS...
# compose
j
Is there a way for TextField to update a
MutableState<String>
with new text ONLY when the text value changes AND when the user clicks off of the text box?
s
Sounds like you’re gonna have two sources of truth for that state then right? Because before they click outside those two states would not be the same. Maybe try listening to the focus of the text field and update this second state of yours when the focus is dropped from that component.
j
Right, but how do I track the focus of the text field
s
Dunno from the top of my head, but there seem to be docs like this https://developer.android.com/jetpack/compose/touch-input/focus or this https://developer.android.com/jetpack/compose/touch-input/focus/react-to-focus which may help you. Otherwise there’s definitely been discussions on focus around this slack channel, search around
j
Awesome, thanks
z
Yea, something like
Copy code
Modifier.onFocusChanged {
  if (!it.isFocused) {
    submittedText = text
  }
}