Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix the shadow issue when scrollX is smaller than the sum of col… #1199

Merged
merged 4 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,10 @@ function Table<RecordType extends DefaultRecordType>(
const measureTarget = currentTarget || scrollHeaderRef.current;
if (measureTarget) {
const scrollWidth =
typeof mergedScrollX === 'number' ? mergedScrollX : measureTarget.scrollWidth;
// Same logic as scrollWidth of useColumns
linxianxi marked this conversation as resolved.
Show resolved Hide resolved
useInternalHooks && tailor && typeof mergedScrollX === 'number'
linxianxi marked this conversation as resolved.
Show resolved Hide resolved
? mergedScrollX
: measureTarget.scrollWidth;
const clientWidth = measureTarget.clientWidth;
// There is no space to scroll
if (scrollWidth === clientWidth) {
Expand Down
34 changes: 34 additions & 0 deletions tests/FixedColumn.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<Table
columns={[
{ title: 'a', width: 200, fixed: 'left' },
{ title: 'b', width: 200 },
{ title: 'c', width: 200 },
{ title: 'd', width: 200, fixed: 'right' },
]}
data={data}
scroll={{ x: 100 }}
style={{ width: 400 }}
/>,
);

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();
});
});
2 changes: 1 addition & 1 deletion tests/__snapshots__/ExpandRow.spec.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ LoadedCheerio {
exports[`Table.Expand > renders fixed column correctly > work 1`] = `
LoadedCheerio {
"0": <div
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"
class="rc-table rc-table-fixed-column rc-table-scroll-horizontal rc-table-has-fix-left rc-table-has-fix-right"
>
<div
class="rc-table-container"
Expand Down
8 changes: 4 additions & 4 deletions tests/__snapshots__/FixedColumn.spec.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ LoadedCheerio {
exports[`Table.FixedColumn > renders correctly > scrollX - with data 1`] = `
LoadedCheerio {
"0": <div
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"
class="rc-table rc-table-fixed-column rc-table-scroll-horizontal rc-table-has-fix-left rc-table-has-fix-right"
>
<div
class="rc-table-container"
Expand Down Expand Up @@ -1642,7 +1642,7 @@ LoadedCheerio {
exports[`Table.FixedColumn > renders correctly > scrollX - without data 1`] = `
LoadedCheerio {
"0": <div
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"
class="rc-table rc-table-fixed-column rc-table-scroll-horizontal rc-table-has-fix-left rc-table-has-fix-right"
>
<div
class="rc-table-container"
Expand Down Expand Up @@ -1931,7 +1931,7 @@ LoadedCheerio {
exports[`Table.FixedColumn > renders correctly > scrollXY - with data 1`] = `
LoadedCheerio {
"0": <div
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"
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"
>
<div
class="rc-table-container"
Expand Down Expand Up @@ -2804,7 +2804,7 @@ LoadedCheerio {
exports[`Table.FixedColumn > renders correctly > scrollXY - without data 1`] = `
LoadedCheerio {
"0": <div
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"
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"
>
<div
class="rc-table-container"
Expand Down