Skip to content

Commit ccbdcab

Browse files
Fix totalHeight calculation in CustomMenuList
Improve the totalHeight calculation to properly iterate through children and use default size for unmeasured items. This addresses a code review comment about potential incorrect height calculations. Co-authored-by: dennisoelkers <41929+dennisoelkers@users.noreply.github.com>
1 parent 1281e77 commit ccbdcab

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

graylog2-web-interface/src/components/common/Select/CustomMenuList.tsx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,23 @@ export const WindowList = ({ children, listRef = undefined, onRowsRendered = und
7070
);
7171

7272
const totalHeight = useMemo(() => {
73-
const sizes = Object.values(sizeMap);
73+
// Calculate total height based on measured sizes
74+
// Only sum heights for items that have been measured
75+
let sum = 0;
7476

75-
return sizes.reduce((sum, size) => {
76-
if (size && sum < MAX_CONTAINER_SIZE) {
77-
return parseInt(String(size), 10) + sum;
77+
for (let i = 0; i < children.length && sum < MAX_CONTAINER_SIZE; i += 1) {
78+
const size = sizeMap[i];
79+
80+
if (size) {
81+
sum += parseInt(String(size), 10);
82+
} else {
83+
// Use default size for unmeasured items
84+
sum += 36;
7885
}
86+
}
7987

80-
return sum;
81-
}, 0);
82-
}, [sizeMap]);
88+
return Math.min(sum, MAX_CONTAINER_SIZE);
89+
}, [sizeMap, children.length]);
8390

8491
const getSize = useCallback((index: number) => sizeMap[index] || 36, [sizeMap]);
8592

0 commit comments

Comments
 (0)