[checkbox group] Focus invalid checkbox - #5216
Conversation
commit: |
Bundle size
PerformanceTotal duration: 1,227.58 ms -73.38 ms(-5.6%) | Renders: 78 (+0) | Paint: 1,930.48 ms -94.03 ms(-4.6%)
12 tests within noise — details Check out the code infra dashboard for more information about this PR. |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Pull request overview
This pull request fixes a form-focus bug in CheckboxGroup when used inside Field.Root, ensuring that invalid submissions focus the checkbox that actually fails native constraint validation (instead of always focusing the first checkbox in the group).
Changes:
- Track registered checkbox inputs (and their corresponding control elements) so focus can target the currently-invalid checkbox within a group.
- Update
CheckboxGroup’s registered field control ref to dynamically resolve to the representative (invalid-first, else first enabled) checkbox control. - Add Chromium-only regression tests covering invalid checkbox focus, unmount/disable scenarios, and parent-checkbox exclusion.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| packages/react/src/internals/field-root-context/FieldRootContext.ts | Extends the default field validation context with getInputControl to support dynamic focus targeting. |
| packages/react/src/field/root/useFieldValidation.ts | Switches registered inputs tracking to a Map and adds getInputControl() to return the representative input’s control element. |
| packages/react/src/checkbox/root/CheckboxRoot.tsx | Registers each checkbox input with its control ref (excluding parent checkboxes) and removes group-level control ref registration. |
| packages/react/src/checkbox-group/CheckboxGroupContext.ts | Removes the now-unneeded registerControlRef from context. |
| packages/react/src/checkbox-group/CheckboxGroup.tsx | Registers a dynamic controlRef whose .current resolves to the representative checkbox control via validation state. |
| packages/react/src/checkbox-group/CheckboxGroup.test.tsx | Adds Chromium-only tests that reproduce and prevent regressions for focus targeting and representative updates. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
7062e67 to
d215a81
Compare
71a19f4 to
358c9e1
Compare
bb953f5 to
21ae3bb
Compare
Fixes #5200
PR #5218 is a smaller dependent follow-up that uses the input registry introduced here.
Changes