https://kotlinlang.org logo
#compose
Title
# compose
r

Rick Regan

02/06/2021, 5:14 PM
Does
Checkbox
have
onCheckedChange: (Boolean) -> Unit
instead of
onClick: () -> Unit
only to support
TriStateCheckbox
? I can see why it's there for that but if you are not using TriStateCheckbox (the normal usage case?) it seems strange that it's just not onClick (like Button, RadioButton, TextButton, and even TriStateCheckbox itself). Why not have a second signature for CheckBox with onClick instead of onCheckedChange?
j

jim

02/06/2021, 5:22 PM
Passing in the "suggested state" (when one exists) is the standard we are trying to encourage for all widgets. This is not so important with such a trivial widget, but gets much more important when widgets have any degree of complexity (eg.
TextField
). The only reason we don't pass in a state for TriStateCheckbox is that the intended "next state" is ambiguous and needs to be decided by the app developer.
r

Rick Regan

02/06/2021, 5:30 PM
OK I think I see the difference now with buttons since there is no suggested state for them, even though as I am using them now I think of them as Boolean ("toggleable"). Thanks.
But wouldn't
RadioButton
have a suggested state of "selected" then? Or is it intentional to omit it to cover groups of radio buttons, where you'd want to deselect the other ones at a higher level?
j

jim

02/06/2021, 7:36 PM
Yeah, for
RadioButton
(which is almost always used in a group and usually you can't deselect all items within the group), the suggested state would always be
true
, which isn't that meaningful.