Is this the gist on how to make a Checkbox with a ...
# compose
c
Is this the gist on how to make a Checkbox with a Text label in compose?
Copy code
var theValue by remember { mutableStateOf(false) }
val doSomething = { theValue = !theValue }
Row(modifier = Modifier.clickable { doSomething() }, verticalAlignment = CenterVertically) {
    Text(text = "Show this: ")
    Checkbox(checked = theValue, onCheckedChange = { doSomething() })
}
or is there something else to have the touch ripples not be independent depending if you click on the row vs the checkbox.
b
You probably want
Modifier.selectable()
with a
Role.Checkbox
to get proper semantics on the row (or
Modifier.triStateToggleable()
if you support the indeterminate state). We are also setting
onCheckedChange = null
on the actual
Checkbox
so it isn’t independently clickable
c
intersting. thanks!
a
For a two-state checkbox,
Modifier.toggleable()
is better semantics-wise. Here’s a similar implementation which uses
Switch
.
c
Thanks @Albert Chang. That makes sense. Was this documented somewhere? Curious where I would go back to look this up as I know it's going to come up like 6 months from now lol
a
Partially mentioned here.
K 1