Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/VirtualTable/BodyGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ const Grid = React.forwardRef<GridRef, GridProps>((props, ref) => {
// ========================== Column ==========================
const columnsWidth = React.useMemo<[key: React.Key, width: number, total: number][]>(() => {
let total = 0;
return flattenColumns.map(({ width, key }) => {
total += width as number;
return [key, width as number, total];
return flattenColumns.map(({ width, minWidth, key }) => {
const finalWidth = Math.max((width as number) || 0, (minWidth as number) || 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While this change correctly introduces minWidth and handles undefined values, the use of as number can be unsafe if width is a string that cannot be cleanly coerced to a number (e.g., '100px'). This would result in NaN from Math.max.

A safer approach is to explicitly convert to a number. This will gracefully handle non-numeric strings by evaluating them to 0 in the Math.max function, preventing NaN values.

      const finalWidth = Math.max(Number(width) || 0, Number(minWidth) || 0);

total += finalWidth;
return [key, finalWidth, total];
});
}, [flattenColumns]);

Expand Down