filterTextContextMenuComponents
Common
Modifier in Compose Foundation
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.
[filter]s added via this modifier will always run after every builder
added via
[Modifier.addTextContextMenuComponents][addTextContextMenuComponents]. 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.addTextContextMenuComponents][addTextContextMenuComponents] have been applied, but the
order in which they run should not be depended on.
Last updated:
Installation
dependencies {
implementation("androidx.compose.foundation:foundation:1.9.0-alpha04")
}
Overloads
fun Modifier.filterTextContextMenuComponents(
filter: (TextContextMenuComponent) -> Boolean
): Modifier
Parameters
name | description |
---|---|
filter | a snapshot-aware lambda that determines whether a [TextContextMenuComponent] should be included in the context menu. |
Code Example
AddFilterToTextContextMenu
@Composable
fun AddFilterToTextContextMenu() {
val textFieldState = rememberTextFieldState()
BasicTextField(
state = textFieldState,
modifier =
Modifier.filterTextContextMenuComponents(
filter = { component -> component.key === ClearKeyDataObject }
),
)
}