1

I have a certain TextField where I needed to specify my padings. enter image description here When there is no text in it, I want to output something like "It's empty here".

Unfortunately, BasicTextField does not allow me to add placeHolder as a modifier. Perhaps you know how to fix this situation? Or you can fix the standard paddings on a regular TextField

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
Rendivy
  • 131
  • 5

1 Answers1

2

In the decorationBox parameter you can add a TextFieldDefaults.OutlinedTextFieldDecorationBox where you can define the placeholder.

Something like:

    var enabled by remember { mutableStateOf(true) }
    val interactionSource = remember { MutableInteractionSource() }

    BasicTextField(
        value = text,
        onValueChange = { text = it },
        singleLine = singleLine,
        interactionSource = interactionSource,
        decorationBox = @Composable { innerTextField ->
            TextFieldDefaults.OutlinedTextFieldDecorationBox(
                value = text,
                innerTextField = innerTextField,
                enabled = enabled,
                singleLine = singleLine,
                visualTransformation = VisualTransformation.None,
                interactionSource = interactionSource,
                placeholder =  { Text("placeholder") }
            )
        }
    )
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
  • I've read the documentation, but I still don't understand what the modifier accepts interactionSource. Could you explain to me? – Rendivy Feb 25 '23 at 19:02