appendTextContextMenuComponents

Functions summary

Modifier

Adds a builder to be run when the text context menu is shown within this hierarchy.

Cmn

Functions

Modifier.appendTextContextMenuComponents

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

Adds a builder 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 builders are applied in order from bottom to top. They are then filtered by every Modifier.filterTextContextMenuComponents in the hierarchy.

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: TextContextMenuBuilderScope.() -> Unit

a snapshot-aware builder function for adding components to the context menu. In this function you can use member functions from the receiver TextContextMenuBuilderScope, such as 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.