From 471422d541f5a5e107de19d714e43fae894f8458 Mon Sep 17 00:00:00 2001 From: linxianxi <904492381@qq.com> Date: Wed, 9 Oct 2024 17:02:47 +0800 Subject: [PATCH 1/4] fix: Fix the shadow issue when scrollX is smaller than the sum of columns --- src/Table.tsx | 5 ++++- tests/FixedColumn.spec.tsx | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/Table.tsx b/src/Table.tsx index 31edce798..1524eec5e 100644 --- a/src/Table.tsx +++ b/src/Table.tsx @@ -455,7 +455,10 @@ function Table( const measureTarget = currentTarget || scrollHeaderRef.current; if (measureTarget) { const scrollWidth = - typeof mergedScrollX === 'number' ? mergedScrollX : measureTarget.scrollWidth; + // Same logic as scrollWidth of useColumns + useInternalHooks && tailor && typeof mergedScrollX === 'number' + ? mergedScrollX + : measureTarget.scrollWidth; const clientWidth = measureTarget.clientWidth; // There is no space to scroll if (scrollWidth === clientWidth) { diff --git a/tests/FixedColumn.spec.tsx b/tests/FixedColumn.spec.tsx index 9e1c95abf..50a21baf9 100644 --- a/tests/FixedColumn.spec.tsx +++ b/tests/FixedColumn.spec.tsx @@ -341,4 +341,38 @@ describe('Table.FixedColumn', () => { expect(container.querySelectorAll('.rc-table-cell-fix-right-first').length).toBe(101); expect(container).toMatchSnapshot(); }); + + it('right shadow should be shown when scrollX is less than the sum of the widths of all columns', async () => { + const wrapper = mount( + , + ); + + await safeAct(wrapper); + // Use `onScroll` directly since simulate not support `currentTarget` + act(() => { + wrapper + .find('.rc-table-content') + .props() + .onScroll({ + currentTarget: { + scrollLeft: 10, + scrollWidth: 800, + clientWidth: 400, + }, + } as any); + }); + wrapper.update(); + expect(wrapper.find('.rc-table').hasClass('rc-table-ping-left')).toBeTruthy(); + expect(wrapper.find('.rc-table').hasClass('rc-table-ping-right')).toBeTruthy(); + }); }); From f5a7c1b7ef1680ef867c5c468d0e8999ddf446f4 Mon Sep 17 00:00:00 2001 From: linxianxi <904492381@qq.com> Date: Wed, 9 Oct 2024 17:08:41 +0800 Subject: [PATCH 2/4] chore: update snapshot --- tests/__snapshots__/FixedColumn.spec.tsx.snap | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/__snapshots__/FixedColumn.spec.tsx.snap b/tests/__snapshots__/FixedColumn.spec.tsx.snap index d108ba0f9..f3091dfd0 100644 --- a/tests/__snapshots__/FixedColumn.spec.tsx.snap +++ b/tests/__snapshots__/FixedColumn.spec.tsx.snap @@ -823,7 +823,7 @@ LoadedCheerio { exports[`Table.FixedColumn > renders correctly > scrollX - with data 1`] = ` LoadedCheerio { "0":
renders correctly > scrollX - without data 1`] = ` LoadedCheerio { "0":
renders correctly > scrollXY - with data 1`] = ` LoadedCheerio { "0":
renders correctly > scrollXY - without data 1`] = ` LoadedCheerio { "0":
Date: Wed, 9 Oct 2024 17:09:09 +0800 Subject: [PATCH 3/4] chore: update snapshot --- tests/__snapshots__/ExpandRow.spec.jsx.snap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/__snapshots__/ExpandRow.spec.jsx.snap b/tests/__snapshots__/ExpandRow.spec.jsx.snap index 72dfbbe21..08b694eff 100644 --- a/tests/__snapshots__/ExpandRow.spec.jsx.snap +++ b/tests/__snapshots__/ExpandRow.spec.jsx.snap @@ -625,7 +625,7 @@ LoadedCheerio { exports[`Table.Expand > renders fixed column correctly > work 1`] = ` LoadedCheerio { "0":
Date: Wed, 9 Oct 2024 17:17:08 +0800 Subject: [PATCH 4/4] chore: adjust comment --- src/Table.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Table.tsx b/src/Table.tsx index 1524eec5e..a1db3de5b 100644 --- a/src/Table.tsx +++ b/src/Table.tsx @@ -455,7 +455,7 @@ function Table( const measureTarget = currentTarget || scrollHeaderRef.current; if (measureTarget) { const scrollWidth = - // Same logic as scrollWidth of useColumns + // Should use mergedScrollX in virtual table(useInternalHooks && tailor === true) useInternalHooks && tailor && typeof mergedScrollX === 'number' ? mergedScrollX : measureTarget.scrollWidth;