Skip to content

Commit 8a7dac0

Browse files
authored
fix: Table header layout when data is empty (#1330)
1 parent b6de81c commit 8a7dac0

File tree

5 files changed

+20
-7
lines changed

5 files changed

+20
-7
lines changed

docs/examples/stickyHeader.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,15 @@ const Demo = () => {
261261
}}
262262
sticky
263263
/>
264+
<br />
265+
<Table
266+
columns={fixedColumns.map(column => ({ ...column, width: undefined }))}
267+
data={[]}
268+
scroll={{
269+
x: 'max-content',
270+
}}
271+
sticky
272+
/>
264273
</div>
265274
);
266275
};

src/FixedHolder/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export interface FixedHeaderProps<RecordType> extends HeaderProps<RecordType> {
3434
stickyTopOffset?: number;
3535
stickyBottomOffset?: number;
3636
stickyClassName?: string;
37+
scrollTableStyle?: React.CSSProperties;
3738
onScroll: (info: { currentTarget: HTMLDivElement; scrollLeft?: number }) => void;
3839
children: (info: HeaderProps<RecordType>) => React.ReactNode;
3940
colGroup?: React.ReactNode;
@@ -58,6 +59,7 @@ const FixedHolder = React.forwardRef<HTMLDivElement, FixedHeaderProps<any>>((pro
5859
stickyTopOffset,
5960
stickyBottomOffset,
6061
stickyClassName,
62+
scrollTableStyle,
6163
onScroll,
6264
children,
6365
...restProps
@@ -148,6 +150,7 @@ const FixedHolder = React.forwardRef<HTMLDivElement, FixedHeaderProps<any>>((pro
148150
style={{
149151
tableLayout: 'fixed',
150152
visibility: noData || mergedColumnWidth ? null : 'hidden',
153+
...scrollTableStyle,
151154
}}
152155
>
153156
{/* use original ColGroup if no data, otherwise use calculated column width */}

src/Table.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,7 @@ function Table<RecordType extends DefaultRecordType>(
684684
...columnContext,
685685
direction,
686686
stickyClassName,
687+
scrollTableStyle,
687688
onScroll: onInternalScroll,
688689
};
689690

tests/__snapshots__/FixedColumn.spec.tsx.snap

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,7 +1941,7 @@ LoadedCheerio {
19411941
style="overflow: hidden;"
19421942
>
19431943
<table
1944-
style="table-layout: fixed;"
1944+
style="table-layout: fixed; width: 1200px; min-width: 100%;"
19451945
>
19461946
<colgroup>
19471947
<col
@@ -2814,7 +2814,7 @@ LoadedCheerio {
28142814
style="overflow: hidden;"
28152815
>
28162816
<table
2817-
style="table-layout: fixed;"
2817+
style="table-layout: fixed; width: 1200px; min-width: 100%;"
28182818
>
28192819
<colgroup>
28202820
<col
@@ -3136,7 +3136,7 @@ exports[`Table.FixedColumn > shadow should be shown when there are columns where
31363136
style="overflow: hidden;"
31373137
>
31383138
<table
3139-
style="table-layout: fixed;"
3139+
style="table-layout: fixed; width: 1500px; min-width: 100%;"
31403140
>
31413141
<colgroup>
31423142
<col
@@ -5567,7 +5567,7 @@ exports[`Table.FixedColumn > shadow should display correctly 1`] = `
55675567
style="overflow: hidden;"
55685568
>
55695569
<table
5570-
style="table-layout: fixed;"
5570+
style="table-layout: fixed; width: 1500px; min-width: 100%;"
55715571
>
55725572
<colgroup>
55735573
<col
@@ -11653,7 +11653,7 @@ exports[`Table.FixedColumn > shadow should display correctly 2`] = `
1165311653
style="overflow: hidden;"
1165411654
>
1165511655
<table
11656-
style="table-layout: fixed;"
11656+
style="table-layout: fixed; width: 1500px; min-width: 100%;"
1165711657
>
1165811658
<colgroup>
1165911659
<col

tests/__snapshots__/Table.spec.jsx.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ LoadedCheerio {
214214
style="overflow: hidden;"
215215
>
216216
<table
217-
style="table-layout: fixed;"
217+
style="table-layout: fixed; width: 100px; min-width: 100%;"
218218
>
219219
<colgroup>
220220
<col
@@ -390,7 +390,7 @@ LoadedCheerio {
390390
style="overflow: hidden;"
391391
>
392392
<table
393-
style="table-layout: fixed;"
393+
style="table-layout: fixed; width: 100px; min-width: 100%;"
394394
>
395395
<colgroup>
396396
<col

0 commit comments

Comments
 (0)