Skip to content

Commit

Permalink
fix(Table): fix sticky table when in iFrame (#1954)
Browse files Browse the repository at this point in the history
  • Loading branch information
tujoworker authored Jan 29, 2023
1 parent 954d570 commit ac4f254
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,6 @@ describe('useStickyHeader', () => {
'304px'
)

// Simulate iFrame
jest.spyOn(window, 'self', 'get').mockReturnValue(null)

rerender(
<Table sticky>
<BasicTable />
Expand All @@ -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', () => {
Expand Down Expand Up @@ -331,9 +325,6 @@ describe('useStickyHeader', () => {
'224px'
)

// Simulate iFrame
jest.spyOn(window, 'self', 'get').mockReturnValue(null)

rerender(
<div className="dnb-modal__content">
<div className="dnb-modal__header__bar">bar</div>
Expand All @@ -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)
})
})

Expand Down

0 comments on commit ac4f254

Please sign in to comment.