Skip to content

Commit c15fe96

Browse files
committed
fix: support react-window 2 in tests
1 parent 235c653 commit c15fe96

1 file changed

Lines changed: 20 additions & 32 deletions

File tree

tests/Table.spec.jsx

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { render, fireEvent } from '@testing-library/react';
22
import { resetWarned } from '@rc-component/util';
33
import React from 'react';
4-
import { VariableSizeGrid as Grid } from 'react-window';
4+
import { Grid } from 'react-window';
55
import Table, { INTERNAL_COL_DEFINE } from '../src';
66
import Cell from '../src/Cell';
77
import { INTERNAL_HOOKS } from '../src/constant';
@@ -1239,58 +1239,46 @@ describe('Table.Basic', () => {
12391239
const obj = {};
12401240
Object.defineProperty(obj, 'scrollLeft', {
12411241
get: () => {
1242-
if (gridRef.current) {
1243-
return gridRef.current?.state?.scrollLeft;
1244-
}
1245-
return null;
1242+
return gridRef.current?.element?.scrollLeft ?? null;
12461243
},
12471244
set: scrollLeft => {
1248-
if (gridRef.current) {
1249-
gridRef.current.scrollTo({ scrollLeft });
1250-
}
1245+
gridRef.current?.element?.scrollTo({ left: scrollLeft });
12511246
},
12521247
});
12531248

12541249
return obj;
12551250
});
12561251

1257-
React.useEffect(() => {
1258-
gridRef.current.resetAfterIndices({
1259-
columnIndex: 0,
1260-
shouldForceUpdate: false,
1261-
});
1262-
}, []);
1252+
const Cell = ({ ariaAttributes, columnIndex, rowIndex, style }) => (
1253+
<div
1254+
{...ariaAttributes}
1255+
className={`virtual-cell ${columnIndex === columns.length - 1 ? 'virtual-cell-last' : ''}`}
1256+
style={style}
1257+
>
1258+
r{rowIndex}, c{columnIndex}
1259+
</div>
1260+
);
12631261

12641262
const renderVirtualList = (rawData, { scrollbarSize, ref, onScroll }) => {
12651263
ref.current = connectObject;
12661264
return (
12671265
<Grid
1268-
ref={gridRef}
1266+
gridRef={gridRef}
12691267
className="virtual-grid"
1268+
cellComponent={Cell}
1269+
cellProps={{}}
12701270
columnCount={columns.length}
12711271
columnWidth={index => {
12721272
const { width } = columns[index];
12731273
return index === columns.length - 1 ? width - scrollbarSize - 1 : width;
12741274
}}
1275-
height={300}
12761275
rowCount={rawData.length}
1277-
rowHeight={() => 50}
1278-
width={800}
1279-
onScroll={({ scrollLeft }) => {
1280-
onScroll({ scrollLeft });
1276+
rowHeight={50}
1277+
style={{ height: 300, width: 800 }}
1278+
onScroll={event => {
1279+
onScroll({ scrollLeft: event.currentTarget.scrollLeft });
12811280
}}
1282-
>
1283-
{({ columnIndex, rowIndex, style }) => (
1284-
<div
1285-
className={`virtual-cell ${
1286-
columnIndex === columns.length - 1 ? 'virtual-cell-last' : ''
1287-
}`}
1288-
style={style}
1289-
>
1290-
r{rowIndex}, c{columnIndex}
1291-
</div>
1292-
)}
1293-
</Grid>
1281+
/>
12941282
);
12951283
};
12961284

0 commit comments

Comments
 (0)