filterTextContextMenuComponents

Compose Modifier

Common
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.

Parameters

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

Code Examples

AddFilterToTextContextMenu

@Composable
fun AddFilterToTextContextMenu() {
    val textFieldState = rememberTextFieldState()
    BasicTextField(
        state = textFieldState,
        modifier =
            Modifier.filterTextContextMenuComponents(
                filter = { component -> component.key === ClearKeyDataObject }
            ),
    )
}