Skip to content

fix: keep popup clicks inside closed shadow roots - #1258

Open
feritcemkahraman wants to merge 2 commits into
react-component:masterfrom
feritcemkahraman:fix/closed-shadow-popup
Open

feritcemkahraman wants to merge 2 commits into
react-component:masterfrom
feritcemkahraman:fix/closed-shadow-popup

Conversation

@feritcemkahraman

@feritcemkahraman feritcemkahraman commented Nov 6, 2026 •

Copy link
Copy Markdown

When a Select popup is rendered in a closed shadow root, clicking inside the popup can close it: the window listener sees the shadow host instead of the clicked element. Preserve the original popup target on the existing mousedown marker so inside clicks stay open and outside clicks still close it. Ref: #1054.

  • pnpm exec rc-test --runInBand: 451 tests and 21 snapshots passed, including a real portal into a separate closed shadow root (jsdom).
  • ESLint on the changed files: 0 errors, 2 existing warnings.
  • tsc --noEmit: 7 errors in existing Jest matcher usages; no errors in the changed files. A real browser was not tested.

Codex assisted with investigation, implementation, and tests.

Summary by CodeRabbit

  • 问题修复
    • 修复 Select 弹窗在闭合 Shadow DOM 中的交互问题:按下弹窗内容时,弹窗不会被误关闭;按下弹窗外部区域时,弹窗仍会正常关闭。

@vercel

vercel Bot commented Nov 6, 2026

Copy link
Copy Markdown

@feritcemkahraman is attempting to deploy a commit to the React Component Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

BaseSelect 在弹出层点击分支中将原始事件目标写入原生事件的 _ori_target 字段。新增测试覆盖两个闭合 Shadow DOM 根中的 Select 和弹出层,并验证不同位置的 mousedown 是否触发关闭。

Changes

闭合 Shadow DOM 点击处理

Layer / File(s) Summary
记录事件目标并验证点击行为
src/BaseSelect/index.tsx, tests/ShadowTrigger.test.tsx
BaseSelect 将原始 target 写入原生事件的 _ori_target 字段。测试使用实际的 @rc-component/trigger,验证弹层内容内的 mousedown 不触发关闭,弹层 Shadow DOM 中的外部元素及 document.body 上的 mousedown 会触发关闭。

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: qdyanbing, nrps9909

Merge Risk: Minimal · up to be4fa

Clicks inside a Select popup rendered in a closed shadow root should no longer close it, and outside clicks still close it. The change is small and covered by a new test, so merge risk is minimal. It was not checked in a real browser.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed 标题“fix: keep popup clicks inside closed shadow roots”与变更内容一致。变更在 src/BaseSelect/index.tsx 的 onRootMouseDown 中把点击目标写入原生事件的 _ori_target 属性,使弹层内点击不会关闭弹层,并新增 ShadowTrigger 测试覆盖闭合 Shadow DOM 场景。标题准确描述了主要修复…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

标题“fix: keep popup clicks inside closed shadow roots”与变更内容一致。变更在 src/BaseSelect/index.tsx 的 onRootMouseDown 中把点击目标写入原生事件的 _ori_target 属性,使弹层内点击不会关闭弹层,并新增 ShadowTrigger 测试覆盖闭合 Shadow DOM 场景。标题准确描述了主要修复点。

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
Fix failing CI checks

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

我是兔子,轻敲弹层边,
原始目标记在事件间。
闭合影根中点一下,
内部不关,外部会收。
测试跑过,月光正圆。

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: cd979a0c-83f3-4369-a120-a2c919e6931f
Commits

Reviewing files that changed from the base of the PR and between dc1c937 and be4fa49.

Files selected for processing: 1

  • src/BaseSelect/index.tsx

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

@codecov

codecov Bot commented Nov 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.46%. Comparing base (dddd067) to head (be4fa49).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1258   +/-   ##
=======================================
  Coverage   99.46%   99.46%           
=======================================
  Files          31       31           
  Lines        1304     1305    +1     
  Branches      476      476           
=======================================
+ Hits         1297     1298    +1     
  Misses          7        7           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread src/BaseSelect/index.tsx

// We should give focus back to selector if clicked item is not focusable
if (popupElement?.contains(target as HTMLElement) && triggerOpen) {
(event.nativeEvent as any)._ori_target = target;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This appears to be a non-standard approach; is there a more standard solution?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants