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()