Parent / child group
A TriStateCheckbox shows On, Off, or Indeterminate for its children.
val children = remember { mutableStateListOf(true, false, false) }
val parentState = when {
children.all { it } -> ToggleableState.On
children.none { it } -> ToggleableState.Off
else -> ToggleableState.Indeterminate
}
TriStateCheckbox(
state = parentState,
onClick = {
val target = parentState != ToggleableState.On
for (i in children.indices) children[i] = target
}
)
children.forEachIndexed { index, checked ->
Checkbox(checked = checked, onCheckedChange = { children[index] = it })
}