---
title: "item"
description: "Adds an item to the list of text context menu components."
type: "function"
---

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


<a id='references'></a>
<div class='sourceset sourceset-android'>Android</div>


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


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

#### Parameters

| | |
| --- | --- |
| key | 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 to display as the text of the item. |
| leadingIcon | 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` means that it will not be displayed. |
| onClick | Action to perform upon the item being clicked/pressed. |




## Code Examples
### AppendItemToTextContextMenuAndroid
```kotlin
@Composable
fun AppendItemToTextContextMenuAndroid() {
    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()
            },
    )
}
```

