Skip to content

[field][select][combobox][slider] Fix label focus in Shadow DOM - #5871

Merged
atomiks merged 3 commits into
mui:masterfrom
lyzno1:codex/fix-label-shadow-root-focus
Oct 5, 2026
Merged

atomiks merged 3 commits into
mui:masterfrom
lyzno1:codex/fix-label-shadow-root-focus

Conversation

@lyzno1

@lyzno1 lyzno1 commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Clicking Select.Label, Combobox.Label, or a non-native Field.Label inside a shadow root currently fails to focus its control. If the outer document contains an element with the same ID, the label can instead focus that unrelated element.

Scope the shared useLabel lookup to the label's root node. Document lookups retain their existing behavior, while shadow-root lookups stay within the same DOM tree. This does not change the public API or custom focus handlers.

StackBlitz reproduction demonstrates the existing Field.Label issue, including an outer-document ID collision.

Regression tests cover supported Select.Label and Combobox.Label compositions and a non-native Field.Label labeling a Select. They verify focus without opening the popup in ordinary DOM and Shadow DOM, with and without an outer matching ID, and preserve native Field.Label activation. All six new Shadow DOM trigger cases failed before the fix in both jsdom and Chromium and pass afterward.

Copilot AI balanced review requested due to automatic review settings October 2, 2026 13:32

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.

Copilot review overview

🟢 Approval recommended

The focused implementation correctly addresses cross-root ID collisions and is comprehensively regression-tested.

Review effort: Balanced
Findings: None

What changed in this PR

Scopes label control lookup to the label’s DOM root, fixing focus behavior in Shadow DOM without changing public APIs.

Changes:

  • Uses root-scoped ID lookup for non-native labels.
  • Adds document, Shadow DOM, ID-collision, popup, and native-label regression tests.
File Description
packages/​react/​src/​internals/​labelable-provider/​useLabel.ts Resolves controls within the label’s root node.
packages/​react/​src/​internals/​labelable-provider/​useLabel.test.tsx Covers label focus across supported DOM compositions.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@pkg-pr-new

pkg-pr-new Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
  • base-ui-tanstack-start

  • vite-css-base-ui-example

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

commit: f56865d

@code-infra-dashboard

code-infra-dashboard Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 🔺+20B(0.00%) 🔺+8B(0.00%)

Details of bundle changes

Performance

Total duration: 551.30 ms +80.35 ms(+17.1%) | Renders: 76 (+0) | Paint: 990.03 ms +118.74 ms(+13.6%)

Test Duration Renders
Scroll Area mount (300 instances) 49.70 ms 🔺+15.53 ms(+45.4%) 3 (+0)
Menu mount (300 instances) 30.48 ms 🔺+8.69 ms(+39.9%) 1 (+0)
Tooltip mount (300 contained roots) 24.05 ms 🔺+7.15 ms(+42.3%) 1 (+0)
Menu open (500 items) 26.01 ms 🔺+5.81 ms(+28.8%) 11 (+0)
Combobox type — 500 items, all stay mounted (type "Row ") 15.91 ms 🔺+3.31 ms(+26.2%) 11 (+0)

…and 1 more (+9 within noise) — details

Metric alarms

Test Metric Change
Scroll Area mount (300 instances) bench:paint 🔺 +15.10 ms
Menu mount (300 instances) bench:paint 🔺 +12.53 ms
Tooltip mount (300 contained roots) bench:paint 🔺 +13.49 ms
Menu open (500 items) bench:paint 🔺 +14.17 ms
Menu open (500 items) bench:paint#menu-open 🔺 +14.17 ms

…and 4 more metric alarms — details


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

@netlify

netlify Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit f56865d
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6ac33e446b9fac00085fa161
😎 Deploy Preview https://deploy-preview-5871--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.

@lyzno1
lyzno1 force-pushed the codex/fix-label-shadow-root-focus branch from 1a4e67c to f799808 Compare October 2, 2026 13:45
@atomiks atomiks added type: bug It doesn't behave as expected. component: select Changes related to the select component. component: combobox Changes related to the combobox component. component: field Changes related to the field component. component: slider Changes related to the slider component. labels Oct 5, 2026
@atomiks atomiks changed the title [field][select][combobox] Fix label focus in Shadow DOM [field][select][combobox][slider] Fix label focus in Shadow DOM Oct 5, 2026
@atomiks
atomiks force-pushed the codex/fix-label-shadow-root-focus branch from d4c930f to ee5d60a Compare October 5, 2026 06:01
@atomiks
atomiks merged commit 4ba59ee into mui:master Oct 5, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: combobox Changes related to the combobox component. component: field Changes related to the field component. component: select Changes related to the select component. component: slider Changes related to the slider component. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants