File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -339,6 +339,16 @@ export const DataTable: FC<DataTableProps> = ({ data }) => {
339
339
const previousTicker = table . getRowModel ( ) . rows [ activeRowIndex - 1 ] . original . ticker ;
340
340
setTicker ( previousTicker ) ;
341
341
}
342
+ event . preventDefault ( ) ;
343
+ const { y } = document . querySelector ( '.grid-row.active' ) ?. getBoundingClientRect ( ) ?? { y : 0 } ;
344
+ if ( Math . round ( y ) <= 0 ) {
345
+ listRef . current ?. scrollToIndex ( {
346
+ index : activeRowIndex - 1 ,
347
+ offset : - 40
348
+ } ) ;
349
+ } else if ( Math . round ( y ) < 120 ) {
350
+ parentRef . current ?. scrollBy ( 0 , - 30 ) ;
351
+ }
342
352
break ;
343
353
}
344
354
case 'ArrowDown' : {
@@ -347,6 +357,18 @@ export const DataTable: FC<DataTableProps> = ({ data }) => {
347
357
const nextTicker = table . getRowModel ( ) . rows [ activeRowIndex + 1 ] . original . ticker ;
348
358
setTicker ( nextTicker ) ;
349
359
}
360
+ event . preventDefault ( ) ;
361
+ const { y } = document . querySelector ( '.grid-row.active' ) ?. getBoundingClientRect ( ) ?? { y : 0 } ;
362
+ const { height } = parentRef . current ?. getBoundingClientRect ( ) ?? { height : 0 } ;
363
+ if ( Math . round ( y ) - Math . round ( height ) > - 10 ) {
364
+ parentRef . current ?. scrollBy ( 0 , 30 + ( y - height ) ) ;
365
+ }
366
+ if ( Math . round ( y ) <= 0 ) {
367
+ listRef . current ?. scrollToIndex ( {
368
+ index : activeRowIndex + 1 ,
369
+ offset : - height + 50
370
+ } ) ;
371
+ }
350
372
break ;
351
373
}
352
374
}
You can’t perform that action at this time.
0 commit comments