From ac4f254973a517faced6edbcb3bf01ca5e672d52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20H=C3=B8egh?= Date: Sun, 29 Jan 2023 19:44:29 +0100 Subject: [PATCH] fix(Table): fix sticky table when in iFrame (#1954) --- .../src/components/table/TableStickyHeader.tsx | 3 +-- .../table/__tests__/TableStickyHeader.test.tsx | 16 ++-------------- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/packages/dnb-eufemia/src/components/table/TableStickyHeader.tsx b/packages/dnb-eufemia/src/components/table/TableStickyHeader.tsx index ea87174b3ee..b5761981440 100644 --- a/packages/dnb-eufemia/src/components/table/TableStickyHeader.tsx +++ b/packages/dnb-eufemia/src/components/table/TableStickyHeader.tsx @@ -51,7 +51,6 @@ export const useStickyHeader = ({ 'thead > tr:first-of-type, thead > .dnb-table__tr:first-of-type' ) const thElem = getThElement(tableElem) - const inIframe = window.self !== window.top const setSizes = () => { offsetTopPx = parseFloat(String(stickyOffset)) || 0 @@ -96,7 +95,7 @@ export const useStickyHeader = ({ thHeight = thElem.offsetHeight tableHeight = tableElem.offsetHeight tableOffset = getOffsetTop(tableElem) - totalOffset = tableOffset - (inIframe ? 0 : offsetTopPx) + totalOffset = tableOffset - offsetTopPx if (sticky === 'css-position') { trElem.style.setProperty( diff --git a/packages/dnb-eufemia/src/components/table/__tests__/TableStickyHeader.test.tsx b/packages/dnb-eufemia/src/components/table/__tests__/TableStickyHeader.test.tsx index e2d4ad90085..515a45a92e0 100644 --- a/packages/dnb-eufemia/src/components/table/__tests__/TableStickyHeader.test.tsx +++ b/packages/dnb-eufemia/src/components/table/__tests__/TableStickyHeader.test.tsx @@ -187,9 +187,6 @@ describe('useStickyHeader', () => { '304px' ) - // Simulate iFrame - jest.spyOn(window, 'self', 'get').mockReturnValue(null) - rerender( @@ -203,9 +200,6 @@ describe('useStickyHeader', () => { expect(trElem.style.getPropertyValue('--table-offset')).toEqual( '160px' ) - - // Reset Simulate iFrame - jest.spyOn(window, 'self', 'get').mockReturnValue(window) }) it('should check if .dnb-scroll-view has a vertical scrollbar and set shadown only, when css-position is used', () => { @@ -331,9 +325,6 @@ describe('useStickyHeader', () => { '224px' ) - // Simulate iFrame - jest.spyOn(window, 'self', 'get').mockReturnValue(null) - rerender(
bar
@@ -347,14 +338,11 @@ describe('useStickyHeader', () => { setSizes() - // Should set correct value (320-(160-0)=160) + // Should set correct value (320-(160-40)=200) simulateScroll(320, scrollElem) expect(trElem.style.getPropertyValue('--table-offset')).toEqual( - '160px' + '200px' ) - - // Reset Simulate iFrame - jest.spyOn(window, 'self', 'get').mockReturnValue(window) }) })