# appendTextContextMenuComponents

Common/All

## Functions summary

|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier.https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/contextmenu/modifier/appendTextContextMenuComponents.modifier#(androidx.compose.ui.Modifier).appendTextContextMenuComponents(kotlin.Function1)(builder: https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/contextmenu/builder/TextContextMenuBuilderScope.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)` Adds a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/contextmenu/modifier/package-summary#(androidx.compose.ui.Modifier).appendTextContextMenuComponents(kotlin.Function1)` to be run when the text context menu is shown within this hierarchy. | Cmn |

## Functions

### Modifier.appendTextContextMenuComponents

Cmn Artifact: [androidx.compose.foundation:foundation](https://developer.android.com/jetpack/androidx/releases/compose-foundation) [View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/text/contextmenu/modifier/TextContextMenuModifier.kt+function:appendTextContextMenuComponents) Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.9.0)

```
fun Modifier.appendTextContextMenuComponents(builder: TextContextMenuBuilderScope.() -> Unit): Modifier
```

Adds a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/contextmenu/modifier/package-summary#(androidx.compose.ui.Modifier).appendTextContextMenuComponents(kotlin.Function1)` to be run when the text context menu is shown within this hierarchy.

When there are multiple instances of this modifier in a layout hierarchy, the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/contextmenu/modifier/package-summary#(androidx.compose.ui.Modifier).appendTextContextMenuComponents(kotlin.Function1)`s are applied in order from bottom to top. They are then filtered by every `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/contextmenu/modifier/filterTextContextMenuComponents.modifier#(androidx.compose.ui.Modifier).filterTextContextMenuComponents(kotlin.Function1)` in the hierarchy.

```kotlin
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.foundation.text.contextmenu.builder.item
import androidx.compose.foundation.text.contextmenu.modifier.appendTextContextMenuComponents
import androidx.compose.foundation.text.input.clearText
import androidx.compose.foundation.text.input.rememberTextFieldState
import androidx.compose.ui.Modifier

val textFieldState = rememberTextFieldState()
BasicTextField(
    state = textFieldState,
    modifier =
        Modifier.appendTextContextMenuComponents {
            separator()
            item(key = ClearKeyDataObject, label = "Clear") {
                textFieldState.clearText()
                close()
            }
            separator()
        },
)
```

| Parameters |
|---|---|
| `builder: https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/contextmenu/builder/TextContextMenuBuilderScope.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | a snapshot-aware builder function for adding components to the context menu. In this function you can use member functions from the receiver `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/contextmenu/builder/TextContextMenuBuilderScope`, such as `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/contextmenu/builder/TextContextMenuBuilderScope#separator()`, to add components. The `item` function is not in the common source set, but is instead defined as an extension function in the platform specific source sets. |