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

(Select-All -> Delete) action in TextField doesn't work when empty text state disposes composition #5023

Open
mgroth0 opened this issue Jun 25, 2024 · 0 comments
Labels
bug Something isn't working submitted

Comments

@mgroth0
Copy link

mgroth0 commented Jun 25, 2024

Describe the bug

In a typical text field, selecting all of the text and pressing the delete key causes all of the text to be deleted.

However, if the text field is set to disapear if the text is empty then this will not work. The TextField flickers. For a brief moment it looks like the text is deleted but it comes right back.

Note that deleting all of the text one deleting one character at a time works fine with the same code.

Affected platforms

  • Desktop (macOS)

Versions

  • Libraries:

    • Compose Multiplatform version: 1.7.0-dev1686
  • Kotlin version: 2.0.0-RC1

  • OS version: MacOS 14.5

  • OS architecture: arm64

  • JDK: 20

To Reproduce
Steps to reproduce the behavior:

  1. Run this code snippet:
import androidx.compose.material3.TextField
import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application

fun main() {
    val text = mutableStateOf("1. Select all of me\n2. Delete")
    application {
        Window(
            onCloseRequest = ::exitApplication
        ) {
            val textValue = text.value
            if (textValue.isNotEmpty()) {
                TextField(
                    value = textValue,
                    onValueChange = {
                        text.value = it
                    }
                )
            }
        }
    }
}
  1. Click on the text
  2. Use the Command-A keyboard shortcut to select all of the text
  3. Press the Delete keyboard button
  4. Observe the textfield flicker, but otherwise the text does not get deleted

Expected behavior

The text should be deleted, and the text field should disapear.

If you delete one character at a time, this behavior can be observed.

Additional context

The reason that my app has a text field like this is because some items can have optional text metadata. It makes sense in my UI because there is a separate way to "add" a text area with template text, but when all of the text gets deleted that is equivalent to the entire text element being deleted.

@mgroth0 mgroth0 added bug Something isn't working submitted labels Jun 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working submitted
Projects
None yet
Development

No branches or pull requests

1 participant