# TextContextMenuBuilderScope

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/builder/TextContextMenuBuilderScope.kt+class:androidx.compose.foundation.text.contextmenu.builder.TextContextMenuBuilderScope) Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.9.0) Common/AllAndroid/JVM
- Cmn

  ```
  class TextContextMenuBuilderScope
  ```

*** ** * ** ***

Scope for building a text context menu in `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/contextmenu/modifier/appendTextContextMenuComponents.modifier#(androidx.compose.ui.Modifier).appendTextContextMenuComponents(kotlin.Function1)`. See member functions for how to add context menu components to this scope as part of the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/contextmenu/modifier/appendTextContextMenuComponents.modifier#(androidx.compose.ui.Modifier).appendTextContextMenuComponents(kotlin.Function1)` modifier. The `item` function is not in the common source set, but is instead defined as an extension function in the platform specific source sets.

## Summary

| ### Public functions |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/contextmenu/builder/TextContextMenuBuilderScope#separator()()` Adds a separator to the list of text context menu components. | Cmn |

| ### Extension functions |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/contextmenu/builder/TextContextMenuBuilderScope.https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/contextmenu/builder/TextContextMenuBuilderScope#(androidx.compose.foundation.text.contextmenu.builder.TextContextMenuBuilderScope).item(kotlin.Any,kotlin.String,kotlin.Int,kotlin.Function1)( key: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html, label: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, leadingIcon: @https://developer.android.com/reference/kotlin/androidx/annotation/DrawableRes https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, onClick: https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/contextmenu/data/TextContextMenuSession.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html )` Adds an item to the list of text context menu components. | android |

## Public functions

### separator

Cmn Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.9.0)

```
fun separator(): Unit
```

Adds a separator to the list of text context menu components. Successive separators will be combined into a single separator.

## Extension functions

### TextContextMenuBuilderScope.item

android 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/builder/TextContextMenuBuilderScope.android.kt+function:item)

```
fun TextContextMenuBuilderScope.item(
    key: Any,
    label: String,
    leadingIcon: @DrawableRes Int = Resources.ID_NULL,
    onClick: TextContextMenuSession.() -> Unit
): Unit
```

Adds an item to the list of text context menu components.

```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
import androidx.compose.ui.res.stringResource

val textFieldState = rememberTextFieldState()
val label = stringResource(R.string.context_menu_clear)
BasicTextField(
    state = textFieldState,
    modifier =
        Modifier.appendTextContextMenuComponents {
            separator()
            item(
                key = ClearKeyDataObject,
                label = label,
                leadingIcon = R.drawable.ic_sample_vector,
            ) {
                textFieldState.clearText()
                close()
            }
            separator()
        },
)
```

| Parameters |
|---|---|
| `key: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html` | A unique key that identifies this item. Used to identify context menu items in the context menu. It is advisable to use a `data object` as a key here. |
| `label: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | string to display as the text of the item. |
| `leadingIcon: @https://developer.android.com/reference/kotlin/androidx/annotation/DrawableRes https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html = Resources.ID_NULL` | Icon that precedes the label in the context menu. This is expected to be a drawable resource reference. Setting this to the default value `https://developer.android.com/reference/android/content/res/Resources.html#ID_NULL` means that it will not be displayed. |
| `onClick: https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/contextmenu/data/TextContextMenuSession.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | Action to perform upon the item being clicked/pressed. |