Property

fillableData

The current value of a component that can be autofilled.

AutofillableTextFieldWithFillableDataSemantics

@Composable
fun AutofillableTextFieldWithFillableDataSemantics() {
    val state = rememberTextFieldState()
    TextField(
        state = state,
        label = { Text("Enter your username here.") },
        modifier =
            Modifier.semantics {
                contentType = ContentType.Username
                // Set the fillable data with semantics.
                FillableData.createFromText(state.text)?.let { fillableData = it }
                // Replace the state value with data from the autofill provider.
                onFillData { savedAutofillValue ->
                    savedAutofillValue.textValue?.let { state.edit { replace(0, length, it) } }
                    true
                }
            },
    )
}