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
6 changes: 4 additions & 2 deletions src/Header/FixedHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function useColumnWidth(colWidths: number[], columCount: number) {
const cloneColumns: number[] = [];
for (let i = 0; i < columCount; i += 1) {
const val = colWidths[i];
if (val) {
if (val !== undefined) {
cloneColumns[i] = val;
} else {
return null;
Expand Down Expand Up @@ -78,7 +78,9 @@ function FixedHeader<RecordType>({
const mergedColumnWidth = useColumnWidth(colWidths, columCount);

return (
<table style={{ tableLayout: 'fixed', visibility: noData || mergedColumnWidth ? null : 'hidden' }}>
<table
style={{ tableLayout: 'fixed', visibility: noData || mergedColumnWidth ? null : 'hidden' }}
>
<ColGroup
colWidths={mergedColumnWidth ? [...mergedColumnWidth, combinationScrollBarSize] : []}
columCount={columCount + 1}
Expand Down
25 changes: 20 additions & 5 deletions tests/FixedHeader.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ describe('Table.FixedHeader', () => {
jest.useFakeTimers();
const col1 = { dataIndex: 'light', width: 100 };
const col2 = { dataIndex: 'bamboo', width: 200 };
const col3 = { dataIndex: 'empty', width: 0 };
const wrapper = mount(
<Table
columns={[col1, col2]}
columns={[col1, col2, col3]}
data={[{ light: 'bamboo', bamboo: 'light', key: 1 }]}
scroll={{ y: 10 }}
/>,
Expand All @@ -26,24 +27,38 @@ describe('Table.FixedHeader', () => {
.at(1)
.props()
.onResize({ width: 200, offsetWidth: 200 });
wrapper
.find('ResizeObserver')
.at(2)
.props()
.onResize({ width: 0, offsetWidth: 0 });

act(() => {
jest.runAllTimers();
wrapper.update();
});

expect(wrapper.find('.rc-table-header table').props().style.visibility).toBeFalsy();

expect();
expect(
wrapper
.find('colgroup col')
.first()
.at(0)
.props().style.width,
).toEqual(100);
expect(
wrapper
.find('colgroup col')
.last()
.at(1)
.props().style.width,
).toEqual(200);
expect(
wrapper
.find('colgroup col')
.at(2)
.props().style.width,
).toEqual(0);

// Update columns
wrapper.setProps({ columns: [col2, col1] });
Expand All @@ -52,13 +67,13 @@ describe('Table.FixedHeader', () => {
expect(
wrapper
.find('colgroup col')
.first()
.at(0)
.props().style.width,
).toEqual(200);
expect(
wrapper
.find('colgroup col')
.last()
.at(1)
.props().style.width,
).toEqual(100);

Expand Down
14 changes: 12 additions & 2 deletions tests/__snapshots__/Table.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,19 @@ exports[`Table.Basic custom components scroll content with scroll 1`] = `
style="overflow: hidden;"
>
<table
style="table-layout: fixed; visibility: hidden;"
style="table-layout: fixed;"
>
<colgroup />
<colgroup>
<col
style="width: 0px; min-width: 0;"
/>
<col
style="width: 888px; min-width: 888px;"
/>
<col
style="width: 15px; min-width: 15px;"
/>
</colgroup>
<thead
class="rc-table-thead"
>
Expand Down