filterTextContextMenuComponents

Functions summary

Modifier

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

Cmn

Functions

Modifier.filterTextContextMenuComponents

fun Modifier.filterTextContextMenuComponents(
    filter: (TextContextMenuComponent) -> Boolean
): Modifier

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

filter will not be passed TextContextMenuSeparator, as they pass by default.

filters added via this modifier will always run after every builder added via Modifier.appendTextContextMenuComponents. When there are multiple instances of this modifier in a layout hierarchy, every filter must pass in order for a context menu to be shown. They are always applied after all Modifier.appendTextContextMenuComponents have been applied, but the order in which they run should not be depended on.

import androidx.compose.foundation.text.BasicTextField
import androidx.compose.foundation.text.contextmenu.modifier.filterTextContextMenuComponents
import androidx.compose.foundation.text.input.rememberTextFieldState
import androidx.compose.ui.Modifier

val textFieldState = rememberTextFieldState()
BasicTextField(
    state = textFieldState,
    modifier =
        Modifier.filterTextContextMenuComponents(
            filter = { component -> component.key === ClearKeyDataObject }
        ),
)
Parameters
filter: (TextContextMenuComponent) -> Boolean

a snapshot-aware lambda that determines whether a TextContextMenuComponent should be included in the context menu.