Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
8 changes: 6 additions & 2 deletions src/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,9 @@ function Table<RecordType extends DefaultRecordType>(

const measureTarget = currentTarget || scrollHeaderRef.current;
if (measureTarget) {
const { scrollWidth, clientWidth } = measureTarget;
const scrollWidth =
typeof mergedScrollX === 'number' ? mergedScrollX : measureTarget.scrollWidth;
const clientWidth = measureTarget.clientWidth;
// There is no space to scroll
if (scrollWidth === clientWidth) {
setPingedLeft(false);
Expand All @@ -481,7 +483,9 @@ function Table<RecordType extends DefaultRecordType>(

const triggerOnScroll = () => {
if (horizonScroll && scrollBodyRef.current) {
onInternalScroll({ currentTarget: scrollBodyRef.current } as React.UIEvent<HTMLDivElement>);
onInternalScroll({
currentTarget: (scrollBodyRef.current as any).nativeElement || scrollBodyRef.current,
} as React.UIEvent<HTMLDivElement>);
} else {
setPingedLeft(false);
setPingedRight(false);
Expand Down
5 changes: 4 additions & 1 deletion src/VirtualTable/BodyGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export interface GridProps<RecordType = any> {

export interface GridRef {
scrollLeft: number;
scrollTo?: (scrollConfig: ScrollConfig) => void;
nativeElement: HTMLDivElement;
scrollTo: (scrollConfig: ScrollConfig) => void;
}

const Grid = React.forwardRef<GridRef, GridProps>((props, ref) => {
Expand Down Expand Up @@ -81,6 +82,7 @@ const Grid = React.forwardRef<GridRef, GridProps>((props, ref) => {
scrollTo: (config: ScrollConfig) => {
listRef.current?.scrollTo(config);
},
nativeElement: listRef.current?.nativeElement,
} as unknown as GridRef;

Object.defineProperty(obj, 'scrollLeft', {
Expand Down Expand Up @@ -236,6 +238,7 @@ const Grid = React.forwardRef<GridRef, GridProps>((props, ref) => {
scrollWidth={scrollX as number}
onVirtualScroll={({ x }) => {
onScroll({
currentTarget: listRef.current?.nativeElement,
scrollLeft: x,
});
}}
Expand Down
2 changes: 1 addition & 1 deletion src/VirtualTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import getValue from 'rc-util/lib/utils/get';
const renderBody: CustomizeScrollBody<any> = (rawData, props) => {
const { ref, onScroll } = props;

return <Grid ref={ref} data={rawData as any} onScroll={onScroll} />;
return <Grid ref={ref as any} data={rawData as any} onScroll={onScroll} />;
};

export interface VirtualTableProps<RecordType> extends Omit<TableProps<RecordType>, 'scroll'> {
Expand Down
75 changes: 75 additions & 0 deletions tests/Virtual.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ describe('Table.Virtual', () => {
},
set: () => {},
},
clientWidth: {
get: () => 80,
},
scrollWidth: {
get: () => 100,
},
});
});

Expand Down Expand Up @@ -443,4 +449,73 @@ describe('Table.Virtual', () => {
fireEvent.scroll(container.querySelector('.rc-table-tbody-virtual-holder')!);
expect(onScroll).toHaveBeenCalled();
});

describe('shadow', () => {
beforeAll(() => {
spyElementPrototypes(HTMLElement, {
scrollLeft: {
get: () => 0,
},
});
});

it('right shadow should display correctly when mount', async () => {
const { container } = getTable({
columns: [
{
dataIndex: 'name',
width: 30,
},
{
dataIndex: 'age',
width: 30,
},
{
dataIndex: 'address',
width: 40,
fixed: 'right',
},
],
getContainerWidth: () => 80,
});

resize(container.querySelector('.rc-table'));

await waitFakeTimer();

expect(
container.querySelector('.rc-table').classList.contains('rc-table-ping-right'),
).toBeTruthy();
});

it('right shadow should display correctly when showHeader is false', async () => {
const { container } = getTable({
showHeader: false,
columns: [
{
dataIndex: 'name',
width: 30,
},
{
dataIndex: 'age',
width: 30,
},
{
dataIndex: 'address',
width: 40,
fixed: 'right',
},
],
getContainerWidth: () => 80,
});

resize(container.querySelector('.rc-table'));

await waitFakeTimer();

expect(
container.querySelector('.rc-table').classList.contains('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-fixed-column rc-table-scroll-horizontal rc-table-has-fix-left rc-table-has-fix-right"
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"
>
<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-fixed-column rc-table-scroll-horizontal rc-table-has-fix-left rc-table-has-fix-right"
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"
>
<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-fixed-column rc-table-scroll-horizontal rc-table-has-fix-left rc-table-has-fix-right"
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"
>
<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-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-ping-right 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-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-ping-right 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