Skip to content

Commit 92dbe91

Browse files
authored
fix: optimize and fix the implementation of emptyNode shake (#1273)
1 parent b4ceb29 commit 92dbe91

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

src/Body/ExpandedRow.tsx

-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ function ExpandedRow(props: ExpandedRowProps) {
6161
className={className}
6262
style={{
6363
display: expanded ? null : 'none',
64-
// fix https://github.com/ant-design/ant-design/issues/49279
65-
visibility: isEmpty && horizonScroll && !componentWidth ? 'hidden' : null,
6664
}}
6765
>
6866
<Cell component={cellComponent} prefixCls={prefixCls} colSpan={colSpan}>

src/Table.tsx

+14-3
Original file line numberDiff line numberDiff line change
@@ -495,9 +495,9 @@ function Table<RecordType extends DefaultRecordType>(
495495
}
496496
};
497497

498-
const onFullTableResize = ({ width }) => {
498+
const onFullTableResize = (offsetWidth?: number) => {
499499
stickyRef.current?.checkScrollBarVisible();
500-
let mergedWidth = fullTableRef.current ? fullTableRef.current.offsetWidth : width;
500+
let mergedWidth = offsetWidth ?? fullTableRef.current?.offsetWidth ?? 0;
501501
if (useInternalHooks && getContainerWidth && fullTableRef.current) {
502502
mergedWidth = getContainerWidth(fullTableRef.current, mergedWidth) || mergedWidth;
503503
}
@@ -508,6 +508,13 @@ function Table<RecordType extends DefaultRecordType>(
508508
}
509509
};
510510

511+
// fix https://github.com/ant-design/ant-design/issues/49279
512+
useLayoutEffect(() => {
513+
if (horizonScroll) {
514+
onFullTableResize();
515+
}
516+
}, [horizonScroll]);
517+
511518
// Sync scroll bar when init or `horizonScroll`, `data` and `columns.length` changed
512519
const mounted = React.useRef(false);
513520
React.useEffect(() => {
@@ -799,7 +806,11 @@ function Table<RecordType extends DefaultRecordType>(
799806
);
800807

801808
if (horizonScroll) {
802-
fullTable = <ResizeObserver onResize={onFullTableResize}>{fullTable}</ResizeObserver>;
809+
fullTable = (
810+
<ResizeObserver onResize={({ offsetWidth }) => onFullTableResize(offsetWidth)}>
811+
{fullTable}
812+
</ResizeObserver>
813+
);
803814
}
804815

805816
const fixedInfoList = useFixedInfo(flattenColumns, stickyOffsets);

tests/__snapshots__/ExpandRow.spec.jsx.snap

+2-2
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ exports[`Table.Expand > renders fixed column correctly > work 1`] = `
569569
>
570570
<div
571571
class="rc-table-expanded-row-fixed"
572-
style="width: 0px; position: sticky; left: 0px; overflow: hidden;"
572+
style="width: 1128px; position: sticky; left: 0px; overflow: hidden;"
573573
>
574574
<p>
575575
extra data
@@ -616,7 +616,7 @@ exports[`Table.Expand > renders fixed column correctly > work 1`] = `
616616
>
617617
<div
618618
class="rc-table-expanded-row-fixed"
619-
style="width: 0px; position: sticky; left: 0px; overflow: hidden;"
619+
style="width: 1128px; position: sticky; left: 0px; overflow: hidden;"
620620
>
621621
<p>
622622
extra data

tests/__snapshots__/FixedColumn.spec.tsx.snap

-2
Original file line numberDiff line numberDiff line change
@@ -1819,7 +1819,6 @@ exports[`Table.FixedColumn > renders correctly > scrollX - without data 1`] = `
18191819
</tr>
18201820
<tr
18211821
class="rc-table-placeholder"
1822-
style=""
18231822
>
18241823
<td
18251824
class="rc-table-cell"
@@ -2976,7 +2975,6 @@ exports[`Table.FixedColumn > renders correctly > scrollXY - without data 1`] = `
29762975
</tr>
29772976
<tr
29782977
class="rc-table-placeholder"
2979-
style=""
29802978
>
29812979
<td
29822980
class="rc-table-cell"

0 commit comments

Comments
 (0)