appendTextContextMenuComponents

Common

Modifier in Compose Foundation

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

Last updated:

Installation

dependencies {
   implementation("androidx.compose.foundation:foundation:1.9.0-beta02")
}

Overloads


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

Parameters

namedescription
buildera 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()][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.

Code Example

AppendComponentsToTextContextMenu

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