-
Notifications
You must be signed in to change notification settings - Fork 333
fix(popover): fix the clickoutside bug in the pop-up component #3899
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughThe popover component's shadow DOM target normalization logic in Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/renderless/src/popover/index.ts (1)
186-205: Shadow DOM containment check correctly narrows target rewriting; consider a small robustness tweak and verify same-host behaviorThe new guard:
if (target?.shadowRoot && target.shadowRoot.contains($el) && popperElm) { target = state.webCompEventTarget as HTMLElement }does what the PR intends: it only rewrites
targetwhen the click comes from a web component host whoseshadowRootactually contains the popover root, so sibling custom elements no longer reusestate.webCompEventTargetand block “click‑outside” closing. This is a good narrowing of the previous behavior.Two follow‑ups to consider:
- Guard the cached target for safety
To avoid ever assigning an undefined/non‑HTMLElement into
targetand to make the intent clearer, you could add an extra check:- if (target?.shadowRoot && target.shadowRoot.contains($el) && popperElm) { - target = state.webCompEventTarget as HTMLElement - } + if ( + target?.shadowRoot && + target.shadowRoot.contains($el) && + popperElm && + state.webCompEventTarget instanceof HTMLElement + ) { + target = state.webCompEventTarget + }This keeps behavior the same in the normal cases but is more defensive.
- Verify clicks inside the same web component but outside popover/reference
Because
state.webCompEventTargetis only updated inhandleClick(bound toreferenceElm), later clicks inside the same web component but outside the popover/reference may still reuse the last cached internal target whentarget.shadowRoot.contains($el)is true. Depending on desired UX, that might mean such clicks are treated as “inside” and won’t close the popover.Please explicitly verify this flow:
- Popover inside a web component host.
- Open popover via
referenceElm.- Click another area inside the same web component but outside both
$elandpopperElm.Confirm whether you expect the popover to close or stay open in that case and adjust logic if needed (for example by clearing or updating
state.webCompEventTargetmore narrowly).
- Unreachable code at the end of
handleDocumentClickThe final
state.showPopper = falseafter theif/elsewithreturnis unreachable and can be safely removed:- } else { - state.showPopper = false - return true - } - - state.showPopper = false + } else { + state.showPopper = false + return true + }Overall, the main fix looks solid; the above are just small robustness/cleanup suggestions and a behavior check for a subtle edge case inside the same host.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/renderless/src/popover/index.ts(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: PR E2E Test (pnpm test:e2e3)
PR
点击 popover 组件外面的webcompont 不能关闭的bug
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
Other information
Summary by CodeRabbit
Release Notes
✏️ Tip: You can customize this high-level summary in your review settings.