huntabyte / bits-ui

The headless components for Svelte.
https://bits-ui.com
MIT License
1.28k stars 94 forks source link

RFC: `Checkbox` `indeterminate` prop vs being a part of `checked` #885

Open huntabyte opened 6 hours ago

huntabyte commented 6 hours ago

Describe the feature in detail (code, mocks, or screenshots encouraged)

I've been thinking it doesn't make a ton of sense to have the checkbox checked state to be of type boolean | 'indeterminate', since there is no way to toggle into indeterminate state after it is initially changed. Perhaps there should be an indeterminate prop that if true will start the checkbox as indeterminate.

This enables us to have checked typed as boolean.

How does everyone feel about this?

What type of pull request would this be?

Enhancement

Provide relevant links or additional information.

No response

ieedan commented 4 hours ago

Personally really like this idea. I really don't like having to check for indeterminate in my code since it ends up adding extra code in my callbacks:

<Checkbox                                                
   onCheckedChange={(checked) => update(checked == 'indeterminate' ? false : checked)}
/>