Skip to content
Merged
Show file tree
Hide file tree
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
11 changes: 9 additions & 2 deletions src/ColGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,18 @@ function ColGroup<RecordType>({ 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(<col key={i} style={{ width, minWidth: width }} {...additionalProps} />);

if (width || additionalProps || mustInsert) {
cols.unshift(<col key={i} style={{ width, minWidth: width }} {...additionalProps} />);
mustInsert = true;
}
}

return <colgroup>{cols}</colgroup>;
Expand Down
1 change: 1 addition & 0 deletions tests/Colgroup.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe('Table.ColGroup', () => {
const columns = [
{
key: 0,
width: 1,
},
];

Expand Down
18 changes: 3 additions & 15 deletions tests/__snapshots__/ExpandRow.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ exports[`Table.Expand childrenColumnName 1`] = `
<table
style="table-layout: auto;"
>
<colgroup>
<col />
<col />
</colgroup>
<colgroup />
<thead
class="rc-table-thead"
>
Expand Down Expand Up @@ -124,9 +121,6 @@ exports[`Table.Expand renders fixed column correctly work 1`] = `
<col
class="rc-table-expand-icon-col"
/>
<col />
<col />
<col />
</colgroup>
<thead
class="rc-table-thead"
Expand Down Expand Up @@ -290,10 +284,7 @@ exports[`Table.Expand renders tree row correctly 1`] = `
<table
style="table-layout: auto;"
>
<colgroup>
<col />
<col />
</colgroup>
<colgroup />
<thead
class="rc-table-thead"
>
Expand Down Expand Up @@ -396,10 +387,7 @@ exports[`Table.Expand renders tree row correctly with different children 1`] = `
<table
style="table-layout: auto;"
>
<colgroup>
<col />
<col />
</colgroup>
<colgroup />
<thead
class="rc-table-thead"
>
Expand Down
42 changes: 9 additions & 33 deletions tests/__snapshots__/Table.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ exports[`Table.Basic custom components renders correctly 1`] = `
name="my-table"
style="table-layout: auto;"
>
<colgroup>
<col />
</colgroup>
<colgroup />
<thead
class="rc-table-thead"
name="my-header-wrapper"
Expand Down Expand Up @@ -133,11 +131,7 @@ exports[`Table.Basic custom components renders fixed column and header correctly
name="my-table"
style="width: 100px; min-width: 100%; table-layout: fixed;"
>
<colgroup>
<col />
<col />
<col />
</colgroup>
<colgroup />
<tbody
class="rc-table-tbody"
name="my-body-wrapper"
Expand Down Expand Up @@ -252,11 +246,7 @@ exports[`Table.Basic internal api transformColumns 1`] = `
<table
style="table-layout: auto;"
>
<colgroup>
<col />
<col />
<col />
</colgroup>
<colgroup />
<thead
class="rc-table-thead"
>
Expand Down Expand Up @@ -333,10 +323,7 @@ exports[`Table.Basic renders colSpan correctly 1`] = `
<table
style="table-layout: auto;"
>
<colgroup>
<col />
<col />
</colgroup>
<colgroup />
<thead
class="rc-table-thead"
>
Expand Down Expand Up @@ -398,9 +385,7 @@ exports[`Table.Basic renders correctly RTL 1`] = `
<table
style="table-layout: auto;"
>
<colgroup>
<col />
</colgroup>
<colgroup />
<thead
class="test-prefix-thead"
>
Expand Down Expand Up @@ -455,9 +440,7 @@ exports[`Table.Basic renders correctly basic 1`] = `
<table
style="table-layout: auto;"
>
<colgroup>
<col />
</colgroup>
<colgroup />
<thead
class="test-prefix-thead"
>
Expand Down Expand Up @@ -512,9 +495,7 @@ exports[`Table.Basic renders correctly no columns 1`] = `
<table
style="table-layout: auto;"
>
<colgroup>
<col />
</colgroup>
<colgroup />
<thead
class="rc-table-thead"
>
Expand Down Expand Up @@ -563,10 +544,7 @@ exports[`Table.Basic renders rowSpan correctly 1`] = `
<table
style="table-layout: auto;"
>
<colgroup>
<col />
<col />
</colgroup>
<colgroup />
<thead
class="rc-table-thead"
>
Expand Down Expand Up @@ -632,9 +610,7 @@ exports[`Table.Basic syntactic sugar 1`] = `
<table
style="table-layout: auto;"
>
<colgroup>
<col />
</colgroup>
<colgroup />
<thead
class="rc-table-thead"
>
Expand Down