https://kotlinlang.org logo
Title
e

eygraber

02/07/2023, 6:19 PM
Is there a way to make a
Text
that has a clickable modifier not be focusable?
a

Alexander Maryanovsky

02/07/2023, 6:45 PM
Try
Modifier.focusProperties{ canFocus = false }
e

eygraber

02/07/2023, 6:48 PM
That didn't work (neither did
focusable(false)
or using both together)
a

Alexander Maryanovsky

02/07/2023, 6:53 PM
The
focusProperties
need to come first. This works for me:
fun main() = singleWindowApplication {
    var text by remember { mutableStateOf("") }
    Column {
        TextField(text, { text = it })
        Text(
            text = "Hello",
            modifier = Modifier
                .focusProperties {
                    canFocus = false
                }
                .clickable {
                    println("Clicked")
                }
        )
    }
}
e

eygraber

02/07/2023, 6:57 PM
Putting them first worked. Thanks!
a

Adam Brown

02/07/2023, 7:30 PM
I know this is compose, not compose desktop related, but the fact that order can subtly and silently break things like this feels like a big weakness of the framework
a

Alexander Maryanovsky

02/07/2023, 7:37 PM
It’s a feature, not a bug. Modifier order matters.
Modifier.padding().border()
is not the same as
Modifier.border().padding()
But I agree that sometimes it’s unexpected
a

Adam Brown

02/07/2023, 7:38 PM
ah I can see that, suppose I just need to get more familiar with it