You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Clicking a TextField should consume the press event (in the Main pass). But instead, it is not consumed and propagates to the parent element.
Affected platforms
Desktop (macOS)
Versions
Libraries:
Compose Multiplatform version: 1.7.0-dev1698
Kotlin version:
OS version(s) (required for Desktop and iOS issues): Mac 14.5 (23F79)
OS architecture (x86 or arm64): arm64
JDK (for desktop issues): 20
To Reproduce
Steps to reproduce the behavior:
Run this code snippet:
importandroidx.compose.foundation.backgroundimportandroidx.compose.foundation.layout.Boximportandroidx.compose.foundation.layout.sizeimportandroidx.compose.material3.TextFieldimportandroidx.compose.runtime.mutableStateOfimportandroidx.compose.ui.ExperimentalComposeUiApiimportandroidx.compose.ui.Modifierimportandroidx.compose.ui.awt.awtEventOrNullimportandroidx.compose.ui.graphics.Colorimportandroidx.compose.ui.input.pointer.PointerEventTypeimportandroidx.compose.ui.input.pointer.onPointerEventimportandroidx.compose.ui.unit.dpimportandroidx.compose.ui.window.Windowimportandroidx.compose.ui.window.application
@OptIn(ExperimentalComposeUiApi::class)
funmain() {
val text = mutableStateOf("some text")
var nextPointerEvent =0
application {
Window(
onCloseRequest = ::exitApplication
) {
Box(
Modifier
.size(400.dp)
.background(Color.Yellow)
.onPointerEvent(PointerEventType.Press) {
val consumed = it.awtEventOrNull!!.isConsumed
text.value ="Got pointer event ${nextPointerEvent++} (consumed=$consumed)"
}
) {
TextField(
value = text.value,
onValueChange = {
text.value = it
}
)
}
}
}
}
Click on the text field
See that the pointer event progated to the parent
Expected behavior
The event handler registered to the container should not receive the click event.
If the pass was PointerEventPass.Initial, then the click event should be received. However, the default value for pass is PointerEventPass.Main. Since the TextField behaves as expected, it seems that the TextField does handle the mouse press event. However, it then fails to consume it and prevent it from propagating further up the tree.
Additional context
I have a mouse click handler on the TextField container in my app. When it receives a click, it uses focusRequester.requestFocus() on its own component. But when the click was actually in the TextField (inside the container), this unexpectedly messes with the focus in the TextField.
The text was updated successfully, but these errors were encountered:
Describe the bug
Clicking a TextField should consume the press event (in the Main pass). But instead, it is not consumed and propagates to the parent element.
Affected platforms
Versions
Libraries:
Kotlin version:
OS version(s) (required for Desktop and iOS issues): Mac 14.5 (23F79)
OS architecture (x86 or arm64): arm64
JDK (for desktop issues): 20
To Reproduce
Steps to reproduce the behavior:
Expected behavior
The event handler registered to the container should not receive the click event.
If the pass was
PointerEventPass.Initial
, then the click event should be received. However, the default value forpass
isPointerEventPass.Main
. Since the TextField behaves as expected, it seems that the TextField does handle the mouse press event. However, it then fails to consume it and prevent it from propagating further up the tree.Additional context
I have a mouse click handler on the TextField container in my app. When it receives a click, it uses
focusRequester.requestFocus()
on its own component. But when the click was actually in the TextField (inside the container), this unexpectedly messes with the focus in the TextField.The text was updated successfully, but these errors were encountered: