---
title: "onFillData"
description: "Action that an autofill service can invoke to fill the component with data.

The [action] will be called by the system, passing the [FillableData] that should be used to
update the component's state.

This is the counterpart to the [fillableData] property, which is used to *provide* the
component's current data to the autofill service."
type: "function"
---

<div class='type'>Function</div>


<a id='references'></a>
<div class='sourceset sourceset-common'>Common</div>


```kotlin
fun SemanticsPropertyReceiver.onFillData(
    label: String? = null,
    action: ((FillableData) -> Boolean)?,
)
```


Action that an autofill service can invoke to fill the component with data.

The `action` will be called by the system, passing the `FillableData` that should be used to
update the component's state.

This is the counterpart to the `fillableData` property, which is used to *provide* the
component's current data to the autofill service.

#### Parameters

| | |
| --- | --- |
| label | Optional label for this action. |
| action | Action to be performed when `SemanticsActions.OnFillData` is called. The lambda receives the `FillableData` from the autofill service. |




## Code Examples
### AutofillableTextFieldWithFillableDataSemantics
```kotlin
@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
                }
            },
    )
}
```

