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 /*