Skip to content

Commit 1253e1f

Browse files
fix: skip iframe html and body in visible area
Co-authored-by: Codex <codex@openai.com>
1 parent 220358d commit 1253e1f

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

src/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export function getVisibleArea(
107107
const visibleArea = { ...initArea };
108108

109109
(scrollerList || []).forEach((ele) => {
110-
if (ele instanceof HTMLBodyElement || ele instanceof HTMLHtmlElement) {
110+
if (ele.tagName === 'BODY' || ele.tagName === 'HTML') {
111111
return;
112112
}
113113

tests/flip.test.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,27 @@ describe('Trigger.Align', () => {
366366
window.getComputedStyle = oriGetComputedStyle;
367367
});
368368

369+
it('skips iframe html and body elements', () => {
370+
const initArea = {
371+
left: 0,
372+
right: 500,
373+
top: 0,
374+
bottom: 500,
375+
};
376+
const iframe = document.createElement('iframe');
377+
document.body.appendChild(iframe);
378+
379+
try {
380+
const { documentElement, body } = iframe.contentDocument!;
381+
382+
expect(getVisibleArea(initArea, [documentElement, body])).toEqual(
383+
initArea,
384+
);
385+
} finally {
386+
iframe.remove();
387+
}
388+
});
389+
369390
// e.g. adjustY + shiftX may make popup out but push back in screen
370391
// which should keep flip
371392
/*

0 commit comments

Comments
 (0)