Skip to content

Commit 29685c2

Browse files
afc163Copilot
andauthored
fix: handle empty or falsy column widths in FixedHolder (#1333)
Co-authored-by: Copilot <[email protected]>
1 parent 024e63e commit 29685c2

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

src/ColGroup.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function ColGroup<RecordType>({ colWidths, columns, columCount }: ColGroupProps<
2222
for (let i = len - 1; i >= 0; i -= 1) {
2323
const width = colWidths[i];
2424
const column = columns && columns[i];
25-
let additionalProps;
25+
let additionalProps: Record<string, unknown>;
2626
let minWidth: number;
2727
if (column) {
2828
additionalProps = column[INTERNAL_COL_DEFINE];

src/FixedHolder/index.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,13 @@ const FixedHolder = React.forwardRef<HTMLDivElement, FixedHeaderProps<any>>((pro
139139

140140
const colGroupNode = useMemo(() => {
141141
// use original ColGroup if no data or no calculated column width, otherwise use calculated column width
142-
if (noData || !mergedColumnWidth) {
142+
// Return original colGroup if no data, or mergedColumnWidth is empty, or all widths are falsy
143+
if (
144+
noData ||
145+
!mergedColumnWidth ||
146+
mergedColumnWidth.length === 0 ||
147+
mergedColumnWidth.every(width => !width)
148+
) {
143149
return colGroup;
144150
}
145151
return (
@@ -149,7 +155,14 @@ const FixedHolder = React.forwardRef<HTMLDivElement, FixedHeaderProps<any>>((pro
149155
columns={flattenColumnsWithScrollbar}
150156
/>
151157
);
152-
}, [noData, mergedColumnWidth, colGroup, combinationScrollBarSize, columCount, flattenColumnsWithScrollbar]);
158+
}, [
159+
noData,
160+
mergedColumnWidth,
161+
colGroup,
162+
combinationScrollBarSize,
163+
columCount,
164+
flattenColumnsWithScrollbar,
165+
]);
153166

154167
return (
155168
<div

tests/__snapshots__/Table.spec.jsx.snap

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -216,20 +216,7 @@ LoadedCheerio {
216216
<table
217217
style="table-layout: fixed; width: 100px; min-width: 100%;"
218218
>
219-
<colgroup>
220-
<col
221-
style="width: 0px;"
222-
/>
223-
<col
224-
style="width: 0px;"
225-
/>
226-
<col
227-
style="width: 0px;"
228-
/>
229-
<col
230-
style="width: 15px;"
231-
/>
232-
</colgroup>
219+
<colgroup />
233220
<thead
234221
class="rc-table-thead"
235222
name="my-header-wrapper"

0 commit comments

Comments
 (0)