|
1 | 1 | import { render, fireEvent } from '@testing-library/react'; |
2 | 2 | import { resetWarned } from '@rc-component/util'; |
3 | 3 | import React from 'react'; |
4 | | -import { VariableSizeGrid as Grid } from 'react-window'; |
| 4 | +import { Grid } from 'react-window'; |
5 | 5 | import Table, { INTERNAL_COL_DEFINE } from '../src'; |
6 | 6 | import Cell from '../src/Cell'; |
7 | 7 | import { INTERNAL_HOOKS } from '../src/constant'; |
@@ -1239,58 +1239,46 @@ describe('Table.Basic', () => { |
1239 | 1239 | const obj = {}; |
1240 | 1240 | Object.defineProperty(obj, 'scrollLeft', { |
1241 | 1241 | get: () => { |
1242 | | - if (gridRef.current) { |
1243 | | - return gridRef.current?.state?.scrollLeft; |
1244 | | - } |
1245 | | - return null; |
| 1242 | + return gridRef.current?.element?.scrollLeft ?? null; |
1246 | 1243 | }, |
1247 | 1244 | set: scrollLeft => { |
1248 | | - if (gridRef.current) { |
1249 | | - gridRef.current.scrollTo({ scrollLeft }); |
1250 | | - } |
| 1245 | + gridRef.current?.element?.scrollTo({ left: scrollLeft }); |
1251 | 1246 | }, |
1252 | 1247 | }); |
1253 | 1248 |
|
1254 | 1249 | return obj; |
1255 | 1250 | }); |
1256 | 1251 |
|
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 | + ); |
1263 | 1261 |
|
1264 | 1262 | const renderVirtualList = (rawData, { scrollbarSize, ref, onScroll }) => { |
1265 | 1263 | ref.current = connectObject; |
1266 | 1264 | return ( |
1267 | 1265 | <Grid |
1268 | | - ref={gridRef} |
| 1266 | + gridRef={gridRef} |
1269 | 1267 | className="virtual-grid" |
| 1268 | + cellComponent={Cell} |
| 1269 | + cellProps={{}} |
1270 | 1270 | columnCount={columns.length} |
1271 | 1271 | columnWidth={index => { |
1272 | 1272 | const { width } = columns[index]; |
1273 | 1273 | return index === columns.length - 1 ? width - scrollbarSize - 1 : width; |
1274 | 1274 | }} |
1275 | | - height={300} |
1276 | 1275 | 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 }); |
1281 | 1280 | }} |
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 | + /> |
1294 | 1282 | ); |
1295 | 1283 | }; |
1296 | 1284 |
|
|
0 commit comments