Closed mahozad closed 2 weeks ago
Describe the bug When removing all the text in a basic text field, the cursor (blinking vertical line) goes to the start of text field instead of staying at center.
Affected platforms
Versions
To Reproduce
fun main() = application { Window(onCloseRequest = ::exitApplication) { MyCustomTextField() } } @OptIn(ExperimentalMaterialApi::class) @Composable private fun MyCustomTextField() { var text by remember { mutableStateOf("1.2.3.4") } val interactionSource = remember(::MutableInteractionSource) Box(contentAlignment = Alignment.CenterEnd, modifier = Modifier.width(500.dp)) { BasicTextField( value = text, onValueChange = { text = it }, cursorBrush = SolidColor(MaterialTheme.colors.onSurface), textStyle = LocalTextStyle.current.copy(textAlign = TextAlign.Center), // <<<<<<<<<<<< ------------- interactionSource = interactionSource, modifier = Modifier .fillMaxWidth() .height(36.dp) .background(Color.LightGray) ) { CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Ltr) { TextFieldDefaults.TextFieldDecorationBox( value = text, innerTextField = it, singleLine = true, enabled = true, placeholder = { Text( text = "hint", style = LocalTextStyle.current.copy(textAlign = TextAlign.Center), fontSize = 9.sp, modifier = Modifier.fillMaxWidth() ) }, visualTransformation = VisualTransformation.None, interactionSource = interactionSource, contentPadding = TextFieldDefaults.textFieldWithoutLabelPadding(top = 0.dp, bottom = 0.dp) ) } } } }
Expected behavior The cursor should stay at center or there should be an option to customize its behavior.
Thanks! It was reported before: https://github.com/JetBrains/compose-multiplatform/issues/4611
Describe the bug When removing all the text in a basic text field, the cursor (blinking vertical line) goes to the start of text field instead of staying at center.
Affected platforms
Versions
To Reproduce
Expected behavior The cursor should stay at center or there should be an option to customize its behavior.