From 1253e1f53e18b7ed222306f3568b9d8d861dd095 Mon Sep 17 00:00:00 2001 From: Pink Champagne <45930107+PinkChampagne17@users.noreply.github.com> Date: Tue, 2 Jun 2026 10:55:28 +0800 Subject: [PATCH] fix: skip iframe html and body in visible area Co-authored-by: Codex --- src/util.ts | 2 +- tests/flip.test.tsx | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/util.ts b/src/util.ts index ba05902a..f7df40da 100644 --- a/src/util.ts +++ b/src/util.ts @@ -107,7 +107,7 @@ export function getVisibleArea( const visibleArea = { ...initArea }; (scrollerList || []).forEach((ele) => { - if (ele instanceof HTMLBodyElement || ele instanceof HTMLHtmlElement) { + if (ele.tagName === 'BODY' || ele.tagName === 'HTML') { return; } diff --git a/tests/flip.test.tsx b/tests/flip.test.tsx index bc1efec6..fc9dad86 100644 --- a/tests/flip.test.tsx +++ b/tests/flip.test.tsx @@ -366,6 +366,27 @@ describe('Trigger.Align', () => { window.getComputedStyle = oriGetComputedStyle; }); + it('skips iframe html and body elements', () => { + const initArea = { + left: 0, + right: 500, + top: 0, + bottom: 500, + }; + const iframe = document.createElement('iframe'); + document.body.appendChild(iframe); + + try { + const { documentElement, body } = iframe.contentDocument!; + + expect(getVisibleArea(initArea, [documentElement, body])).toEqual( + initArea, + ); + } finally { + iframe.remove(); + } + }); + // e.g. adjustY + shiftX may make popup out but push back in screen // which should keep flip /*