Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

next(breaking): change checked type for checkbox components #898

Merged
merged 3 commits into from
Nov 9, 2024

Conversation

huntabyte
Copy link
Owner

@huntabyte huntabyte commented Nov 9, 2024

Having the checked state be boolean | 'indeterminate' is quite annoying, especially considering from a user's perspective, once you leave the 'indeterminate' state, you can't toggle back to it.

This PR changes the checked props to be boolean and adds an indeterminate prop which is also of type boolean.

If you wish to have a checkbox in an indeterminate state, you can simply do the following:

<Checkbox.Root indeterminate />

By default, when a user clicks an indeterminate checkbox, it will change checked to true and indeterminate to false.

indeterminate can be controlled, so you can programmatically put a checkbox back into the indeterminate state if you wish, using the normal state management strategies (bind:indeterminate, onIndeterminateChange, controlledIndeterminate).

I've wanted to make this change for some time and many others have expressed frustration with always having to conditionally check the type when working with things that expect a boolean.

Additionally, the snippet props for the Checkbox and *Menu.CheckboxItem components have been adjusted to expose both a checked and indeterminate prop:

<Checkbox.Root>
	{#snippet children({ checked, indeterminate })}
		{#if indeterminate}
			-
		{:else if checked}
			✅
		{/if}	
	{/snippet}
</Checkbox.Root>

Closes #885

Copy link

changeset-bot bot commented Nov 9, 2024

🦋 Changeset detected

Latest commit: dcb5f06

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
bits-ui Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

github-actions bot commented Nov 9, 2024

built with Refined Cloudflare Pages Action

⚡ Cloudflare Pages Deployment

Name Status Preview Last Commit
bits-ui ✅ Ready (View Log) Visit Preview dcb5f06

@huntabyte huntabyte changed the title next(Breaking): change checked type for checkbox components next(breaking): change checked type for checkbox components Nov 9, 2024
@huntabyte huntabyte merged commit 60ea79c into next Nov 9, 2024
5 checks passed
@huntabyte huntabyte deleted the next-checkbox-indeterminate branch November 9, 2024 18:21
@github-actions github-actions bot mentioned this pull request Nov 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant