-
Notifications
You must be signed in to change notification settings - Fork 170
fix: Do not bail on calculating position of popover if its trigger is inside Shadow DOM #3429
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,10 +63,14 @@ export default function usePopoverPosition({ | |
const document = popover.ownerDocument; | ||
const track = trackRef.current; | ||
|
||
const rootNode = popover.getRootNode(); | ||
const isInShadowDom = rootNode !== document && rootNode.nodeType === Node.DOCUMENT_FRAGMENT_NODE; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this check There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will have to double-check this, but my first thought is that the iframe's document is not a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right. I haven't realised that is not the global document but
|
||
|
||
// If the popover body isn't being rendered for whatever reason (e.g. "display: none" or JSDOM), | ||
// or track does not belong to the document - bail on calculating dimensions. | ||
const { offsetWidth, offsetHeight } = getOffsetDimensions(popover); | ||
if (offsetWidth === 0 || offsetHeight === 0 || !nodeContains(document.body, track)) { | ||
|
||
if (offsetWidth === 0 || offsetHeight === 0 || !nodeContains(isInShadowDom ? rootNode : document.body, track)) { | ||
return; | ||
} | ||
|
||
|
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.
Considering the complications of supporting the click() event, how about we scope the tests to the popover container (internal) component instead? You can add a new test file
popover-container.test.tsx
and assert the expected placement, but without the need to make it visible first.