I want to listen to 'Backspace' key down events but only when it is not used to delete characters in a Text Field.
I expected that 'somehow' the text field would consume such events and not let anyone else handle it, but it doesnt seem to be the same.
I am working on JVM + JS. Not sure if that changes anything
Any ideas how to block events from bubbling up? Code in 🧵
Alex Styl
10/03/2024, 5:10 PM
This is an oversimplified example. In reality The box is at the App() while the basic text field is nested inside multiple composables
Copy code
Box(
modifier = Modifier.onKeyEvent {
error("This should never trigger while typing on the Text Field")
false
}
) {
BasicTextField(
modifier = modifier,
value = value,
singleLine = singleLine,
onValueChange = onValueChange,
)
}
Alex Styl
10/03/2024, 5:17 PM
Ok figured it out. I can consume the events using the
onKeyEvent{}
on the Text field.
Copy code
BasicTextField(
value = text,
onValueChange = {
text = it
},
modifier = Modifier.onKeyEvent {
true
}
)