Skip to content

Commit 9908afe

Browse files
committed
Guard fractional spacer height against padding and borders
1 parent e474cfa commit 9908afe

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

‎src/Components/Web.JS/src/Virtualize.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,17 @@ function getScaleFactor(spacerBefore: HTMLElement, spacerAfter: HTMLElement): nu
7272
return 1;
7373
}
7474
const measuredHeight = el.getBoundingClientRect().height;
75+
const offsetHeight = el.offsetHeight;
7576
const declaredHeight = parseFloat(el.style.height);
7677
// offsetHeight is rounded to whole pixels. For fractional row heights the ratio then
7778
// drifts from 1 even without a zoom or transform, so use the fractional declared height
78-
// when the spacer has one.
79-
const scale = Number.isFinite(declaredHeight) && declaredHeight > 0
79+
// when the spacer has one. A content-box padding or border makes the rendered box larger
80+
// than the declared content height; fall back to the rendered box in that case.
81+
const useDeclaredHeight = Number.isFinite(declaredHeight) && declaredHeight > 0 &&
82+
Math.abs(declaredHeight - offsetHeight) <= 1;
83+
const scale = useDeclaredHeight
8084
? measuredHeight / declaredHeight
81-
: measuredHeight / el.offsetHeight;
85+
: measuredHeight / offsetHeight;
8286
return (Number.isFinite(scale) && scale > 0) ? scale : 1;
8387
}
8488

0 commit comments

Comments
 (0)