Start native apps faster with the Composables CLI ->
Property

hintText

The hint text for an editable text field.

HintTextSample

@Sampled
@Composable
fun HintTextSample() {
    val label = "Label" // In an application, this hint would typically be a localized String.
    var text by remember { mutableStateOf("") }
    BasicTextField(
        value = text,
        onValueChange = { text = it },
        modifier = Modifier.semantics { hintText = label },
        decorationBox = { innerTextField ->
            Box {
                innerTextField()
                if (text.isEmpty()) {
                    // Hide this visual placeholder from talkback to prevent duplicated
                    // announcements, as the parent BasicTextField already provides the hintText.
                    Text(text = label, modifier = Modifier.semantics { hideFromAccessibility() })
                }
            }
        },
    )
}