From 392b9c8e717f9a937573c3db0a17d50d0d4a3132 Mon Sep 17 00:00:00 2001 From: Petyo Ivanov Date: Fri, 6 Aug 2021 10:32:56 +0300 Subject: [PATCH] fix(): improve size handling on different zoom levels Fixes #423 More information about the issue here: https://bugs.chromium.org/p/chromium/issues/detail?id=608142 --- src/sizeSystem.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/sizeSystem.ts b/src/sizeSystem.ts index 3e7a7066e..6d26f44a6 100644 --- a/src/sizeSystem.ts +++ b/src/sizeSystem.ts @@ -228,6 +228,11 @@ export function hasGroups(sizes: SizeState) { type OptionalNumber = number | undefined +const SIZE_MAP = { + offsetHeight: 'height', + offsetWidth: 'width', +} as const + /** Calculates the height of `el`, which will be the `Item` element in the DOM. */ export type SizeFunction = (el: HTMLElement, field: 'offsetHeight' | 'offsetWidth') => number @@ -240,7 +245,7 @@ export const sizeSystem = u.system( const groupIndices = u.statefulStream([] as number[]) const fixedItemSize = u.statefulStream(undefined) const defaultItemSize = u.statefulStream(undefined) - const itemSize = u.statefulStream((el, field) => el[field]) + const itemSize = u.statefulStream((el, field) => el.getBoundingClientRect()[SIZE_MAP[field]]) const data = u.statefulStream(undefined) const initial = initialSizeState()