# androidx.compose.foundation.text.contextmenu.builder

# androidx.compose.foundation.text.contextmenu.builder

Common/AllAndroid/JVM

## Classes

|----------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----|
| [TextContextMenuBuilderScope](https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/contextmenu/builder/TextContextMenuBuilderScope) | Scope for building a text context menu in[Modifier.appendTextContextMenuComponents](https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/contextmenu/modifier/package-summary#(androidx.compose.ui.Modifier).appendTextContextMenuComponents(kotlin.Function1)). | Cmn |

## Extension functions summary

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

## Extension functions

### 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: `[Any](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: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)                                                                                                                                                           | string to display as the text of the item.                                                                                                                                                                                                                                             |
| `leadingIcon: @`[DrawableRes](https://developer.android.com/reference/kotlin/androidx/annotation/DrawableRes)` `[Int](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[Resources.ID_NULL](https://developer.android.com/reference/android/content/res/Resources.html#ID_NULL())means that it will not be displayed. |
| `onClick: `[TextContextMenuSession](https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/contextmenu/data/TextContextMenuSession)`.() `->` `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | Action to perform upon the item being clicked/pressed.                                                                                                                                                                                                                                 |