Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pressing the return key in TextField triggers the parent container's clickable #4612

Closed
y-sugitani opened this issue Apr 13, 2024 · 3 comments
Labels
bug Something isn't working input Touch, mouse, keyboard input related upstream (AOSP) Issue is in Google issue tracker

Comments

@y-sugitani
Copy link

y-sugitani commented Apr 13, 2024

Describe the bug
When focusing on a TextField and displaying the virtual keyboard, pressing the return key triggers the clickable set on the parent container that contains the TextField. This may cause unintended behavior.

Affected platforms

  • Android

Versions

  • Kotlin version: 1.9.22
  • Compose Multiplatform version: 1.6.2
  • OS version(s): Android 14
  • Device: Pixel 7a

To Reproduce

  1. Create a new Compose Multiplatform project
  2. Add the following code:
@Composable
@Preview
fun App() {
    val focusManager = LocalFocusManager.current
    var text by remember { mutableStateOf("") }
    var background by remember { mutableStateOf(Color.LightGray) }

    Box(
        modifier =
        Modifier
            .imePadding()
            .fillMaxWidth()
            .height(100.dp)
            .background(background)
            .clickable(
                interactionSource = remember { MutableInteractionSource() },
                indication = null,
                onClick = {
                    background = Color.Red
                    focusManager.clearFocus()
                },
            ),
        contentAlignment = Alignment.Center
    ) {
        OutlinedTextField(
            value = text,
            onValueChange = { text = it },
        )
    }
}
  1. Run the app on an Android device or emulator
  2. Tap the TextField to focus it and display the virtual keyboard
  3. Press the return key on the virtual keyboard
  4. The parent container's clickable is triggered, and the background color changes to red

Expected behavior
Pressing the return key in the TextField should not trigger the parent container's clickable, and a line break should occur within the TextField.

Screenshots

android.mp4

Additional context
This behavior was observed on a Pixel 7a running Android 14. It is unknown whether the same behavior occurs on other devices or OS versions.

A reproducible project is available at https://github.com/blackcat-carnival/compose-bugreport-202404-02

@y-sugitani y-sugitani added bug Something isn't working submitted labels Apr 13, 2024
@m-sasha
Copy link
Contributor

m-sasha commented Apr 16, 2024

The problem here is that the TextField reacts to, and consumes, the KeyDown event, while clickable reacts to KeyUp events.

The fix is probably to either have the textfield also consume the KeyUp for any consumed KeyDown, or for clickable to ignore KeyUp events whose KeyDown it didn't receive.

@m-sasha
Copy link
Contributor

m-sasha commented Apr 16, 2024

Since this is an issue upstream, please report it in the Android bug tracker: https://issuetracker.google.com/issues?q=status:open%20componentid:612128&s=created_time:desc

@m-sasha m-sasha added upstream (AOSP) Issue is in Google issue tracker input Touch, mouse, keyboard input related and removed submitted labels Apr 16, 2024
@y-sugitani
Copy link
Author

Thank you for your response and the detailed explanation. With this information, I should be able to work around the issue in my project. Your help is much appreciated.

I have reported the bug to the Google Issue Tracker at https://issuetracker.google.com/issues/335342650

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working input Touch, mouse, keyboard input related upstream (AOSP) Issue is in Google issue tracker
Projects
None yet
Development

No branches or pull requests

2 participants