Skip to content

Commit d2be6e6

Browse files
committed
Add support for disabling scroll to active cell
1 parent 752f8f8 commit d2be6e6

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

packages/core/src/data-editor/data-editor.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,11 @@ export interface DataEditorProps extends Props, Pick<DataGridSearchProps, "image
660660
* Allows overriding the default amount of bloom (the size growth of the overlay editor)
661661
*/
662662
readonly editorBloom?: readonly [number, number];
663+
664+
/**
665+
* If set to true, the data grid will attempt to scroll to keep the selction in view
666+
*/
667+
readonly scrollToActiveCell?: boolean;
663668
}
664669

665670
type ScrollToFn = (
@@ -847,6 +852,7 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
847852
isOutsideClick,
848853
renderers,
849854
resizeIndicator,
855+
scrollToActiveCell = true,
850856
} = p;
851857

852858
const rowMarkersObj = typeof p.rowMarkers === "string" ? undefined : p.rowMarkers;
@@ -2843,6 +2849,9 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
28432849
]
28442850
);
28452851

2852+
const scrollToActiveCellRef = React.useRef(scrollToActiveCell);
2853+
scrollToActiveCellRef.current = scrollToActiveCell;
2854+
28462855
const updateSelectedCell = React.useCallback(
28472856
(col: number, row: number, fromEditingTrailingRow: boolean, freeMove: boolean): boolean => {
28482857
const rowMax = mangledRows - (fromEditingTrailingRow ? 0 : 1);
@@ -2885,7 +2894,9 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
28852894
lastSent.current = undefined;
28862895
}
28872896

2888-
scrollTo(col - rowMarkerOffset, row);
2897+
if (scrollToActiveCellRef.current) {
2898+
scrollTo(col - rowMarkerOffset, row);
2899+
}
28892900

28902901
return true;
28912902
},
@@ -3720,6 +3731,7 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
37203731
scrollToRef.current = scrollTo;
37213732
React.useLayoutEffect(() => {
37223733
if (
3734+
scrollToActiveCellRef.current &&
37233735
!hasJustScrolled.current &&
37243736
outCol !== undefined &&
37253737
outRow !== undefined &&

0 commit comments

Comments
 (0)