Skip to content

Conversation

edmolima
Copy link

@edmolima edmolima commented Oct 2, 2025

Fixes #2691

Context

In the "parent checkbox" use case of CheckboxGroup, the consumer-specified id on Checkbox.Root was being ignored. This made it impossible to associate a label to the checkbox using htmlFor.

The issue occurred because useCheckboxGroupParent was returning its own generated id in getParentProps(), which overrode the user-provided id prop.

Summary

  • Modified getParentProps() to accept an optional parentId parameter
  • CheckboxRoot now passes itsid to getParentProps() for parent checkboxes
  • This ensures custom id props are honored and aria-controls uses the correct id

Test plan

  • Added test to verify custom id is respected on parent checkbox
  • Added test to verify label association via htmlFor works correctly
  • All existing tests pass"

I have followed (at least) the PR section of the contributing guide.

Copy link

pkg-pr-new bot commented Oct 2, 2025

vite-css-base-ui-example

pnpm add https://pkg.pr.new/mui/base-ui/@base-ui-components/react@2896
pnpm add https://pkg.pr.new/mui/base-ui/@base-ui-components/utils@2896

commit: 8780294

Copy link

netlify bot commented Oct 2, 2025

Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 8780294
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/68df69fc01a2d000083ebe19
😎 Deploy Preview https://deploy-preview-2896--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@edmolima edmolima marked this pull request as draft October 2, 2025 22:13
@edmolima edmolima marked this pull request as ready for review October 2, 2025 22:14
@mj12albert mj12albert added the component: checkbox group Changes related to the checkbox group component. label Oct 3, 2025
@mj12albert
Copy link
Member

@edmolima I tested this PR using the original repro: https://codesandbox.io/p/sandbox/base-ui-checkbox-nested-bug-forked-zkhqtl

A custom id on non-parent checkboxes doesn't work still (which the OP's sandbox demonstrates), as clicking the label doesn't toggle the checkbox

@mj12albert mj12albert changed the title [checkbox group] Fix parent checkbox ignoring custom id prop (#2691) [checkbox group] Fix parent checkbox ignoring custom id prop Oct 3, 2025
…=20(staff) groups=20(staff),12(everyone),61(localaccounts),79(_appserverusr),80(admin),81(_appserveradm),33(_appstore),98(_lpadmin),100(_lpoperator),204(_developer),250(_analyticsusers),395(com.apple.access_ftp),398(com.apple.access_screensharing),399(com.apple.access_ssh),400(com.apple.access_remote_ae),701(com.apple.sharepoint.group.1) prop
@edmolima edmolima marked this pull request as draft October 3, 2025 06:15
@edmolima edmolima marked this pull request as ready for review October 3, 2025 06:31
@edmolima
Copy link
Author

edmolima commented Oct 3, 2025

Hey @mj12albert!

Thanks for testing this and catching the issue!

I added a new test, and right now everything looks good.

The playground is here to easily the test again:
https://codesandbox.io/p/sandbox/base-ui-checkbox-nested-bug-forked-4gzlc6

indeterminate,
checked,
'aria-controls': allValues.map((v) => `${id}-${v}`).join(' '),
'aria-controls': allValues.map((v) => `${parentId ?? id}-${v}`).join(' '),
Copy link
Member

Choose a reason for hiding this comment

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

aria-controls here also needs to reference custom child ids when present

This is where it gets complicated, I think for this to work all the children need to register their ids with the parent, currently the parent is just deriving them from allValues

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Oct 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: checkbox group Changes related to the checkbox group component. PR: out-of-date The pull request has merge conflicts and can't be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[checkbox][CheckboxGroup] Checkbox.Root id not working in "parent checkbox" use case
2 participants