From e742bbdc798ee5163f0f74fed2fdbe025544e031 Mon Sep 17 00:00:00 2001 From: linxianxi <904492381@qq.com> Date: Thu, 15 May 2025 10:58:49 +0800 Subject: [PATCH] fix: optimize and fix the implementation of emptyNode shake --- src/Body/ExpandedRow.tsx | 2 -- src/Table.tsx | 17 ++++++++++++++--- tests/__snapshots__/ExpandRow.spec.jsx.snap | 4 ++-- tests/__snapshots__/FixedColumn.spec.tsx.snap | 2 -- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/Body/ExpandedRow.tsx b/src/Body/ExpandedRow.tsx index 593ba298d..b4009601c 100644 --- a/src/Body/ExpandedRow.tsx +++ b/src/Body/ExpandedRow.tsx @@ -61,8 +61,6 @@ function ExpandedRow(props: ExpandedRowProps) { className={className} style={{ display: expanded ? null : 'none', - // fix https://github.com/ant-design/ant-design/issues/49279 - visibility: isEmpty && horizonScroll && !componentWidth ? 'hidden' : null, }} > diff --git a/src/Table.tsx b/src/Table.tsx index 299a48b35..f6676abcd 100644 --- a/src/Table.tsx +++ b/src/Table.tsx @@ -495,9 +495,9 @@ function Table( } }; - const onFullTableResize = ({ width }) => { + const onFullTableResize = (offsetWidth?: number) => { stickyRef.current?.checkScrollBarVisible(); - let mergedWidth = fullTableRef.current ? fullTableRef.current.offsetWidth : width; + let mergedWidth = offsetWidth ?? fullTableRef.current?.offsetWidth ?? 0; if (useInternalHooks && getContainerWidth && fullTableRef.current) { mergedWidth = getContainerWidth(fullTableRef.current, mergedWidth) || mergedWidth; } @@ -508,6 +508,13 @@ function Table( } }; + // fix https://github.com/ant-design/ant-design/issues/49279 + useLayoutEffect(() => { + if (horizonScroll) { + onFullTableResize(); + } + }, [horizonScroll]); + // Sync scroll bar when init or `horizonScroll`, `data` and `columns.length` changed const mounted = React.useRef(false); React.useEffect(() => { @@ -799,7 +806,11 @@ function Table( ); if (horizonScroll) { - fullTable = {fullTable}; + fullTable = ( + onFullTableResize(offsetWidth)}> + {fullTable} + + ); } const fixedInfoList = useFixedInfo(flattenColumns, stickyOffsets); diff --git a/tests/__snapshots__/ExpandRow.spec.jsx.snap b/tests/__snapshots__/ExpandRow.spec.jsx.snap index e59681a83..68961386d 100644 --- a/tests/__snapshots__/ExpandRow.spec.jsx.snap +++ b/tests/__snapshots__/ExpandRow.spec.jsx.snap @@ -569,7 +569,7 @@ exports[`Table.Expand > renders fixed column correctly > work 1`] = ` >

extra data @@ -616,7 +616,7 @@ exports[`Table.Expand > renders fixed column correctly > work 1`] = ` >

extra data diff --git a/tests/__snapshots__/FixedColumn.spec.tsx.snap b/tests/__snapshots__/FixedColumn.spec.tsx.snap index acbb24071..4e7b289b4 100644 --- a/tests/__snapshots__/FixedColumn.spec.tsx.snap +++ b/tests/__snapshots__/FixedColumn.spec.tsx.snap @@ -1819,7 +1819,6 @@ exports[`Table.FixedColumn > renders correctly > scrollX - without data 1`] = ` renders correctly > scrollXY - without data 1`] = `