Repository navigation
[field][select][combobox][slider] Fix label focus in Shadow DOM - #5871
Conversation
There was a problem hiding this comment.
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.
commit: |
Bundle size
PerformanceTotal duration: 551.30 ms +80.35 ms(+17.1%) | Renders: 76 (+0) | Paint: 990.03 ms +118.74 ms(+13.6%)
…and 1 more (+9 within noise) — details Metric alarms
…and 4 more metric alarms — 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. |
1a4e67c to
f799808
Compare
d4c930f to
ee5d60a
Compare
Clicking
Select.Label,Combobox.Label, or a non-nativeField.Labelinside 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
useLabellookup 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.