Skip to content

Commit bfa65ba

Browse files
authored
fix: Fix the shadow issue when scrollX is smaller than the sum of col… (#1199)
* fix: Fix the shadow issue when scrollX is smaller than the sum of columns * chore: update snapshot * chore: update snapshot * chore: adjust comment
1 parent 7755ae0 commit bfa65ba

File tree

4 files changed

+43
-6
lines changed

4 files changed

+43
-6
lines changed

src/Table.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,10 @@ function Table<RecordType extends DefaultRecordType>(
455455
const measureTarget = currentTarget || scrollHeaderRef.current;
456456
if (measureTarget) {
457457
const scrollWidth =
458-
typeof mergedScrollX === 'number' ? mergedScrollX : measureTarget.scrollWidth;
458+
// Should use mergedScrollX in virtual table(useInternalHooks && tailor === true)
459+
useInternalHooks && tailor && typeof mergedScrollX === 'number'
460+
? mergedScrollX
461+
: measureTarget.scrollWidth;
459462
const clientWidth = measureTarget.clientWidth;
460463
// There is no space to scroll
461464
if (scrollWidth === clientWidth) {

tests/FixedColumn.spec.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,4 +341,38 @@ describe('Table.FixedColumn', () => {
341341
expect(container.querySelectorAll('.rc-table-cell-fix-right-first').length).toBe(101);
342342
expect(container).toMatchSnapshot();
343343
});
344+
345+
it('right shadow should be shown when scrollX is less than the sum of the widths of all columns', async () => {
346+
const wrapper = mount(
347+
<Table
348+
columns={[
349+
{ title: 'a', width: 200, fixed: 'left' },
350+
{ title: 'b', width: 200 },
351+
{ title: 'c', width: 200 },
352+
{ title: 'd', width: 200, fixed: 'right' },
353+
]}
354+
data={data}
355+
scroll={{ x: 100 }}
356+
style={{ width: 400 }}
357+
/>,
358+
);
359+
360+
await safeAct(wrapper);
361+
// Use `onScroll` directly since simulate not support `currentTarget`
362+
act(() => {
363+
wrapper
364+
.find('.rc-table-content')
365+
.props()
366+
.onScroll({
367+
currentTarget: {
368+
scrollLeft: 10,
369+
scrollWidth: 800,
370+
clientWidth: 400,
371+
},
372+
} as any);
373+
});
374+
wrapper.update();
375+
expect(wrapper.find('.rc-table').hasClass('rc-table-ping-left')).toBeTruthy();
376+
expect(wrapper.find('.rc-table').hasClass('rc-table-ping-right')).toBeTruthy();
377+
});
344378
});

tests/__snapshots__/ExpandRow.spec.jsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ LoadedCheerio {
625625
exports[`Table.Expand > renders fixed column correctly > work 1`] = `
626626
LoadedCheerio {
627627
"0": <div
628-
class="rc-table rc-table-ping-right rc-table-fixed-column rc-table-scroll-horizontal rc-table-has-fix-left rc-table-has-fix-right"
628+
class="rc-table rc-table-fixed-column rc-table-scroll-horizontal rc-table-has-fix-left rc-table-has-fix-right"
629629
>
630630
<div
631631
class="rc-table-container"

tests/__snapshots__/FixedColumn.spec.tsx.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ LoadedCheerio {
823823
exports[`Table.FixedColumn > renders correctly > scrollX - with data 1`] = `
824824
LoadedCheerio {
825825
"0": <div
826-
class="rc-table rc-table-ping-right rc-table-fixed-column rc-table-scroll-horizontal rc-table-has-fix-left rc-table-has-fix-right"
826+
class="rc-table rc-table-fixed-column rc-table-scroll-horizontal rc-table-has-fix-left rc-table-has-fix-right"
827827
>
828828
<div
829829
class="rc-table-container"
@@ -1642,7 +1642,7 @@ LoadedCheerio {
16421642
exports[`Table.FixedColumn > renders correctly > scrollX - without data 1`] = `
16431643
LoadedCheerio {
16441644
"0": <div
1645-
class="rc-table rc-table-ping-right rc-table-fixed-column rc-table-scroll-horizontal rc-table-has-fix-left rc-table-has-fix-right"
1645+
class="rc-table rc-table-fixed-column rc-table-scroll-horizontal rc-table-has-fix-left rc-table-has-fix-right"
16461646
>
16471647
<div
16481648
class="rc-table-container"
@@ -1931,7 +1931,7 @@ LoadedCheerio {
19311931
exports[`Table.FixedColumn > renders correctly > scrollXY - with data 1`] = `
19321932
LoadedCheerio {
19331933
"0": <div
1934-
class="rc-table rc-table-ping-right rc-table-fixed-header rc-table-fixed-column rc-table-scroll-horizontal rc-table-has-fix-left rc-table-has-fix-right"
1934+
class="rc-table rc-table-fixed-header rc-table-fixed-column rc-table-scroll-horizontal rc-table-has-fix-left rc-table-has-fix-right"
19351935
>
19361936
<div
19371937
class="rc-table-container"
@@ -2804,7 +2804,7 @@ LoadedCheerio {
28042804
exports[`Table.FixedColumn > renders correctly > scrollXY - without data 1`] = `
28052805
LoadedCheerio {
28062806
"0": <div
2807-
class="rc-table rc-table-ping-right rc-table-fixed-header rc-table-fixed-column rc-table-scroll-horizontal rc-table-has-fix-left rc-table-has-fix-right"
2807+
class="rc-table rc-table-fixed-header rc-table-fixed-column rc-table-scroll-horizontal rc-table-has-fix-left rc-table-has-fix-right"
28082808
>
28092809
<div
28102810
class="rc-table-container"

0 commit comments

Comments
 (0)