-
-
Notifications
You must be signed in to change notification settings - Fork 244
[checkbox group] Fix parent checkbox ignoring custom id
prop
#2896
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
base: master
Are you sure you want to change the base?
Conversation
commit: |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
@edmolima I tested this PR using the original repro: https://codesandbox.io/p/sandbox/base-ui-checkbox-nested-bug-forked-zkhqtl A custom |
id
prop (#2691)id
prop
…=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
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: |
indeterminate, | ||
checked, | ||
'aria-controls': allValues.map((v) => `${id}-${v}`).join(' '), | ||
'aria-controls': allValues.map((v) => `${parentId ?? id}-${v}`).join(' '), |
There was a problem hiding this comment.
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 id
s when present
This is where it gets complicated, I think for this to work all the children need to register their id
s with the parent, currently the parent is just deriving them from allValues
Fixes #2691
Context
In the "parent checkbox" use case of CheckboxGroup, the consumer-specified
id
onCheckbox.Root
was being ignored. This made it impossible to associate a label to the checkbox usinghtmlFor
.The issue occurred because
useCheckboxGroupParent
was returning its own generatedid
ingetParentProps()
, which overrode the user-providedid
prop.Summary
getParentProps()
to accept an optionalparentId
parameterCheckboxRoot
now passes itsid
togetParentProps()
for parent checkboxesid
props are honored andaria-controls
uses the correct idTest plan
id
is respected on parent checkboxhtmlFor
works correctlyI have followed (at least) the PR section of the contributing guide.