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.
    val state = rememberTextFieldState()
    BasicTextField(
        state = state,
        modifier = Modifier.semantics { hintText = label },
        decorator = { innerTextField ->
            Box {
                innerTextField()
                if (state.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() })
                }
            }
        },
    )
}

Content updated: