Skip to content

Commit 838f30d

Browse files
fix table measurement
1 parent dcc62c5 commit 838f30d

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

assets/design-system/src/components/table/tableUtils.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,33 @@ export function measureElement(
112112
element: Element,
113113
dimension: 'height' | 'width' = 'height'
114114
): number {
115+
// <tr> uses display: contents; measure rendered cell boxes instead of Range,
116+
// which over-reports height for clamped cell content and breaks virtual scroll.
117+
if (element.tagName === 'TR' && element.children.length > 0) {
118+
let maxSize = 0
119+
120+
for (const child of element.children) {
121+
const size =
122+
dimension === 'width'
123+
? (child as HTMLElement).offsetWidth
124+
: (child as HTMLElement).offsetHeight
125+
126+
if (size > maxSize) maxSize = size
127+
}
128+
129+
if (maxSize > 0) return maxSize
130+
}
131+
115132
const { width, height } = element.getBoundingClientRect()
116133
const value = dimension === 'width' ? width : height
117-
// Since <tr>s are rendered with `display: contents`, we need to calculate
118-
// row height/width from contents using Range
134+
119135
if (value <= 0 && element?.hasChildNodes()) {
120136
const range = document.createRange()
121137
range.setStart(element, 0)
122138
range.setEnd(element, element.childNodes.length)
123139
const { width, height } = range.getBoundingClientRect()
124140
return dimension === 'width' ? width : height
125141
}
142+
126143
return value
127144
}

0 commit comments

Comments
 (0)