Colton Idle

    Colton Idle

    10 months ago
    Is this the gist on how to make a Checkbox with a Text label in compose?
    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.
    Bryan Herbst

    Bryan Herbst

    10 months ago
    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
    Colton Idle

    Colton Idle

    10 months ago
    intersting. thanks!
    Albert Chang

    Albert Chang

    10 months ago
    For a two-state checkbox,
    Modifier.toggleable()
    is better semantics-wise. Here’s a similar implementation which uses
    Switch
    .
    Colton Idle

    Colton Idle

    10 months ago
    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
    Albert Chang

    Albert Chang

    10 months ago
    Partially mentioned here.