I'm working on an edit screen in Jetpack Compose and seeing behavior where, when I tap the text field for the first time, the cursor appears at the beginning of the text in the field, rather than at the end.
OutlinedTextField(
value = user.name,
onValueChange = { onChange(user.copy(name = it)) },
modifier = Modifier.fillMaxWidth(),
label = { Text(text = stringResource(R.string.name)) },
singleLine = true,
enabled = enabled,
)
The screen shows up and the "Name" field appears populated. But when I tap into the field, the cursor appears at the beginning of the field.
When I debug, the field never renders where user.name
is null or empty. I can move the cursor around and edit the text fine after the initial tap.
My goal is to avoid tapping twice to put the cursor at the end.
I tried having it go through a run where the user.name
was ""
before the real value gets passed to see if it needed some kind of "appending" to occur. But even with that the cursor appeared at the front on the first tap.
I also tried rendering the field with just the string "test"
to see if that would place the cursor at the end. Also no, still at the front.
EDIT: seems like this is a bug somewhere. Created a minimally reproducible example and submitted a bug: https://issuetracker.google.com/issues/275157249
As best I can tell, if the text field is part of the first composition, the cursor will be at the beginning of the field, regardless of the text inside.