Skip to content

checkbox: Add unstable Provider, Trigger and BubbleInput #3459

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

Merged
merged 7 commits into from
Apr 30, 2025

Conversation

chaance
Copy link
Member

@chaance chaance commented Apr 10, 2025

This PR introduces new parts for the Checkbox component. This change is intended to test out a new pattern that we can replicate for other form controls.

Currently our form control components will try to detect whether or not they are associated with a form, and if so, render a hidden input so that native events bubble to the form itself. While this can make behavior feel more like native form elements, the downside is that it adds an additional element that is hard to control and not always what users expect.

The goal is the hand control back to the user. So instead of Checkbox.Root rendering both a provider and an input, users can opt in and render the parts that they want.

// before
<Checkbox.Root>
  <Checkbox.Indicator />
</Checkbox.Root>

// after
<Checkbox.Provider>
  <Checkbox.Trigger>
    <Checkbox.Indicator />
  </Checkbox.Trigger>
</Checkbox.Provider>

Currently these parts are prefixed with unstable_ since we may want to consider the API more deeply before committing to these patterns. Should we decide to move forward, in a future version we'd probably rename Checkbox.Provider to Checkbox.Root and get rid of the pre-composed version entirely.

Related:

Copy link

changeset-bot bot commented Apr 10, 2025

🦋 Changeset detected

Latest commit: 777f739

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

This PR includes changesets to release 2 packages
Name Type
@radix-ui/react-checkbox Minor
radix-ui Minor

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

@chaance chaance requested a review from lucasmotta April 10, 2025 23:17
});
});

describe('given a controlled Checkbox in a form', () => {
afterEach(cleanup);
describe('Legacy Checkbox', () => {
Copy link
Member Author

@chaance chaance Apr 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left these tests unchanged but moved them into a nested describe block. The diffs look silly, but everything above this block is new, everything below is old.

@chaance chaance force-pushed the chance/split-checkbox-components branch from 89186e3 to 777f739 Compare April 22, 2025 17:50
@chaance chaance merged commit 42a39f4 into main Apr 30, 2025
2 checks passed
@chaance chaance deleted the chance/split-checkbox-components branch April 30, 2025 00:13
@github-actions github-actions bot mentioned this pull request May 5, 2025
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