Skip to content

[checkbox group] Focus invalid checkbox - #5216

Merged
atomiks merged 3 commits into
mui:masterfrom
atomiks:codex/checkbox-group-invalid-focus
Jul 15, 2026
Merged

[checkbox group] Focus invalid checkbox#5216
atomiks merged 3 commits into
mui:masterfrom
atomiks:codex/checkbox-group-invalid-focus

Conversation

@atomiks

@atomiks atomiks commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Fixes #5200

PR #5218 is a smaller dependent follow-up that uses the input registry introduced here.

Changes

  • Focuses the checkbox whose hidden input fails validation.
  • Keeps input registration and focus targeting synchronized across disabled, unmounted, portaled, and reassociated checkboxes.
  • Preserves validation mode boundaries when no eligible checkbox is mounted while still running custom validation at the configured boundary.

@atomiks atomiks added component: checkbox group Changes related to the checkbox group component. type: bug It doesn't behave as expected. labels Jul 13, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jul 13, 2026

Copy link
Copy Markdown

commit: 21ae3bb

@code-infra-dashboard

code-infra-dashboard Bot commented Jul 13, 2026

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 🔺+448B(+0.10%) 🔺+184B(+0.13%)

Details of bundle changes

Performance

Total duration: 1,227.58 ms -73.38 ms(-5.6%) | Renders: 78 (+0) | Paint: 1,930.48 ms -94.03 ms(-4.6%)

Test Duration Renders
Combobox type — 500 items, narrows to ~11 (type "Row 25") 33.17 ms ▼-13.90 ms(-29.5%) 17 (+0)
Combobox type — 500 items, all stay mounted (type "Row ") 28.27 ms ▼-8.39 ms(-22.9%) 11 (+0)

12 tests within noise — details


Check out the code infra dashboard for more information about this PR.

@netlify

netlify Bot commented Jul 13, 2026

Copy link
Copy Markdown

Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 21ae3bb
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a5747c27454430007a6d2da
😎 Deploy Preview https://deploy-preview-5216--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

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

@atomiks
atomiks requested a review from Copilot July 13, 2026 10:03
@atomiks
atomiks marked this pull request as ready for review July 13, 2026 10:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jul 13, 2026
@atomiks
atomiks force-pushed the codex/checkbox-group-invalid-focus branch from 7062e67 to d215a81 Compare July 14, 2026 04:39
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jul 14, 2026
@atomiks
atomiks force-pushed the codex/checkbox-group-invalid-focus branch 2 times, most recently from 71a19f4 to 358c9e1 Compare July 15, 2026 06:56
@atomiks
atomiks requested a review from Copilot July 15, 2026 08:17

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Comment thread packages/react/src/field/root/useFieldValidation.ts Outdated
@atomiks
atomiks force-pushed the codex/checkbox-group-invalid-focus branch from bb953f5 to 21ae3bb Compare July 15, 2026 08:41
@atomiks
atomiks merged commit 8e11f43 into mui:master Jul 15, 2026
24 checks passed
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. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[checkbox group] Invalid form submission focuses the first checkbox instead of the checkbox that failed validation

2 participants