@@ -85,7 +85,7 @@ type DefaultColumnOptions<R, SR> = Pick<
85
85
86
86
export interface DataGridHandle {
87
87
element : HTMLDivElement | null ;
88
- scrollToCell : ( position : PartialPosition ) => void ;
88
+ scrollToCell : ( position : PartialPosition , scrollIntoViewOptions ?: boolean | ScrollIntoViewOptions ) => void ;
89
89
selectCell : ( position : Position , enableEditor ?: Maybe < boolean > ) => void ;
90
90
}
91
91
@@ -293,6 +293,7 @@ function DataGrid<R, SR, K extends Key>(
293
293
const lastSelectedRowIdx = useRef ( - 1 ) ;
294
294
const focusSinkRef = useRef < HTMLDivElement > ( null ) ;
295
295
const shouldFocusCellRef = useRef ( false ) ;
296
+ const scrollIntoViewOptions = useRef < boolean | ScrollIntoViewOptions > ( ) ;
296
297
297
298
/**
298
299
* computed values
@@ -441,13 +442,14 @@ function DataGrid<R, SR, K extends Key>(
441
442
442
443
useImperativeHandle ( ref , ( ) => ( {
443
444
element : gridRef . current ,
444
- scrollToCell ( { idx, rowIdx } ) {
445
+ scrollToCell ( { idx, rowIdx } , options ) {
445
446
const scrollToIdx =
446
447
idx !== undefined && idx > lastFrozenColumnIndex && idx < columns . length ? idx : undefined ;
447
448
const scrollToRowIdx =
448
449
rowIdx !== undefined && isRowIdxWithinViewportBounds ( rowIdx ) ? rowIdx : undefined ;
449
450
450
451
if ( scrollToIdx !== undefined || scrollToRowIdx !== undefined ) {
452
+ scrollIntoViewOptions . current = options ;
451
453
setScrollToPosition ( { idx : scrollToIdx , rowIdx : scrollToRowIdx } ) ;
452
454
}
453
455
} ,
@@ -678,7 +680,11 @@ function DataGrid<R, SR, K extends Key>(
678
680
) ;
679
681
}
680
682
681
- function selectCell ( position : Position , enableEditor ?: Maybe < boolean > ) : void {
683
+ function selectCell (
684
+ position : Position ,
685
+ enableEditor ?: Maybe < boolean > ,
686
+ scrollIntoViewOptions ?: boolean | ScrollIntoViewOptions
687
+ ) : void {
682
688
if ( ! isCellWithinSelectionBounds ( position ) ) return ;
683
689
commitEditorChanges ( ) ;
684
690
@@ -687,7 +693,7 @@ function DataGrid<R, SR, K extends Key>(
687
693
setSelectedPosition ( { ...position , mode : 'EDIT' , row, originalRow : row } ) ;
688
694
} else if ( isSamePosition ( selectedPosition , position ) ) {
689
695
// Avoid re-renders if the selected cell state is the same
690
- scrollIntoView ( getCellToScroll ( gridRef . current ! ) ) ;
696
+ scrollIntoView ( getCellToScroll ( gridRef . current ! ) , scrollIntoViewOptions ) ;
691
697
} else {
692
698
shouldFocusCellRef . current = true ;
693
699
setSelectedPosition ( { ...position , mode : 'SELECT' } ) ;
@@ -1125,6 +1131,7 @@ function DataGrid<R, SR, K extends Key>(
1125
1131
scrollToPosition = { scrollToPosition }
1126
1132
setScrollToCellPosition = { setScrollToPosition }
1127
1133
gridElement = { gridRef . current ! }
1134
+ scrollIntoViewOptions = { scrollIntoViewOptions . current }
1128
1135
/>
1129
1136
) }
1130
1137
</ div >
0 commit comments