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 1 commit
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 @@ -96,7 +96,7 @@
]);
});
await safeAct(wrapper);
expect(wrapper.render()).toMatchSnapshot();

Check failure on line 99 in tests/FixedColumn.spec.tsx

View workflow job for this annotation

GitHub Actions / test / react component workflow

tests/FixedColumn.spec.tsx > Table.FixedColumn > renders correctly > scrollX - with data

Error: Snapshot `Table.FixedColumn > renders correctly > scrollX - with data 1` mismatched - Expected + Received @@ -1,8 +1,8 @@ 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" > <div ❯ tests/FixedColumn.spec.tsx:99:36

Check failure on line 99 in tests/FixedColumn.spec.tsx

View workflow job for this annotation

GitHub Actions / test / react component workflow

tests/FixedColumn.spec.tsx > Table.FixedColumn > renders correctly > scrollX - without data

Error: Snapshot `Table.FixedColumn > renders correctly > scrollX - without data 1` mismatched - Expected + Received @@ -1,8 +1,8 @@ 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" > <div ❯ tests/FixedColumn.spec.tsx:99:36

Check failure on line 99 in tests/FixedColumn.spec.tsx

View workflow job for this annotation

GitHub Actions / test / react component workflow

tests/FixedColumn.spec.tsx > Table.FixedColumn > renders correctly > scrollXY - with data

Error: Snapshot `Table.FixedColumn > renders correctly > scrollXY - with data 1` mismatched - Expected + Received @@ -1,8 +1,8 @@ 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" > <div ❯ tests/FixedColumn.spec.tsx:99:36

Check failure on line 99 in tests/FixedColumn.spec.tsx

View workflow job for this annotation

GitHub Actions / test / react component workflow

tests/FixedColumn.spec.tsx > Table.FixedColumn > renders correctly > scrollXY - without data

Error: Snapshot `Table.FixedColumn > renders correctly > scrollXY - without data 1` mismatched - Expected + Received @@ -1,8 +1,8 @@ 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" > <div ❯ tests/FixedColumn.spec.tsx:99:36
vi.useRealTimers();
});
});
Expand Down Expand Up @@ -341,4 +341,38 @@
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();
});
});
Loading