diff --git a/src/ColGroup.tsx b/src/ColGroup.tsx index b4271f38b..9630d6431 100644 --- a/src/ColGroup.tsx +++ b/src/ColGroup.tsx @@ -12,11 +12,18 @@ function ColGroup({ colWidths, columns, columCount }: ColGroupProps< const cols: React.ReactElement[] = []; const len = columCount || columns.length; - for (let i = 0; i < len; i += 1) { + // Only insert col with width & additional props + // Skip if rest col do not have any useful info + let mustInsert = false; + for (let i = len - 1; i >= 0; i -= 1) { const width = colWidths[i]; const column = columns && columns[i]; const additionalProps = column && column[INTERNAL_COL_DEFINE]; - cols.push(); + + if (width || additionalProps || mustInsert) { + cols.unshift(); + mustInsert = true; + } } return {cols}; diff --git a/tests/Colgroup.spec.js b/tests/Colgroup.spec.js index c47225fd8..1b88224f6 100644 --- a/tests/Colgroup.spec.js +++ b/tests/Colgroup.spec.js @@ -19,6 +19,7 @@ describe('Table.ColGroup', () => { const columns = [ { key: 0, + width: 1, }, ]; diff --git a/tests/__snapshots__/ExpandRow.spec.js.snap b/tests/__snapshots__/ExpandRow.spec.js.snap index 0aef8f1ea..42d27d8c3 100644 --- a/tests/__snapshots__/ExpandRow.spec.js.snap +++ b/tests/__snapshots__/ExpandRow.spec.js.snap @@ -13,10 +13,7 @@ exports[`Table.Expand childrenColumnName 1`] = ` - - - - + @@ -124,9 +121,6 @@ exports[`Table.Expand renders fixed column correctly work 1`] = ` - - - - - - - + @@ -396,10 +387,7 @@ exports[`Table.Expand renders tree row correctly with different children 1`] = `
- - - - + diff --git a/tests/__snapshots__/Table.spec.js.snap b/tests/__snapshots__/Table.spec.js.snap index 9c965678b..ab1e514af 100644 --- a/tests/__snapshots__/Table.spec.js.snap +++ b/tests/__snapshots__/Table.spec.js.snap @@ -14,9 +14,7 @@ exports[`Table.Basic custom components renders correctly 1`] = ` name="my-table" style="table-layout: auto;" > - - - + - - - - - + - - - - - + @@ -333,10 +323,7 @@ exports[`Table.Basic renders colSpan correctly 1`] = `
- - - - + @@ -398,9 +385,7 @@ exports[`Table.Basic renders correctly RTL 1`] = `
- - - + @@ -455,9 +440,7 @@ exports[`Table.Basic renders correctly basic 1`] = `
- - - + @@ -512,9 +495,7 @@ exports[`Table.Basic renders correctly no columns 1`] = `
- - - + @@ -563,10 +544,7 @@ exports[`Table.Basic renders rowSpan correctly 1`] = `
- - - - + @@ -632,9 +610,7 @@ exports[`Table.Basic syntactic sugar 1`] = `
- - - +