https://kotlinlang.org logo
Title
s

spierce7

05/29/2021, 7:33 PM
What’s the best way to center a label vertically in an
OutlinedTextField
. I can’t seem to find a good way.
val userState = remember { mutableStateOf(TextFieldValue()) }
        OutlinedTextField(
            value = userState.value,
            onValueChange = { userState.value = it },
            label = {
                Text("User")
            },
        )

        Spacer(Modifier.height(10.dp))

        val passwordState = remember { mutableStateOf(TextFieldValue()) }
        val hidePassword = remember { mutableStateOf(true) }
        OutlinedTextField(
            value = passwordState.value,
            onValueChange = { passwordState.value = it },
            label = { Text("Password") },
            visualTransformation = if (hidePassword.value) PasswordVisualTransformation() else VisualTransformation.None,
            keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Password),
        )
k

Kirill Grouchnikov

05/29/2021, 10:10 PM
File a bug if
OutlinedTextField
is not up to the Material Design spec from https://material.io/components/text-fields#outlined-text-field
s

spierce7

05/29/2021, 11:42 PM
d

Denis Ismailaj

05/30/2021, 2:03 PM
Not sure about compose desktop but on compose for android you'd have to set the parameter
singleLine
to true for the label to be centered
s

spierce7

05/31/2021, 5:52 AM
Thanks @Denis Ismailaj . That was the problem. Setting
singleLine = true
fixes it. Closing the ticket.