diff --git a/packages/core/src/data-editor/data-editor.tsx b/packages/core/src/data-editor/data-editor.tsx index 2d81fe286..c15158f78 100644 --- a/packages/core/src/data-editor/data-editor.tsx +++ b/packages/core/src/data-editor/data-editor.tsx @@ -467,6 +467,12 @@ export interface DataEditorProps extends Props { * @group Selection */ readonly gridSelection?: GridSelection; + /** + * Scroll position configuration when using {@link gridSelection}. + * See "Controlled selection" example for details. + * @group Selection + */ + readonly gridSelectionScrollOptions?: GridSelectionScrollOptions; /** * Emitted whenever the grid selection changes. Specifying * this function will make the grid’s selection controlled, so @@ -610,16 +616,26 @@ export interface DataEditorProps extends Props { readonly scaleToRem?: boolean; } +type GridSelectionScrollOptions = { + dir?: ScrollDir; + paddingX?: number; + paddingY?: number; + options?: ScrollAlignOptions; +}; + +type ScrollDir = "horizontal" | "vertical" | "both"; +type ScrollAlignOptions = { + hAlign?: "start" | "center" | "end"; + vAlign?: "start" | "center" | "end"; +}; + type ScrollToFn = ( col: number | { amount: number; unit: "cell" | "px" }, row: number | { amount: number; unit: "cell" | "px" }, - dir?: "horizontal" | "vertical" | "both", + dir?: ScrollDir, paddingX?: number, paddingY?: number, - options?: { - hAlign?: "start" | "center" | "end"; - vAlign?: "start" | "center" | "end"; - } + options?: ScrollAlignOptions ) => void; /** @category DataEditor */ @@ -743,6 +759,7 @@ const DataEditorImpl: React.ForwardRefRenderFunction { rows: CompactSelection.empty(), }); + const [centerScroll, setCenterScroll] = React.useState(false); + const handleCenterScroll = () => setCenterScroll(s => !s); + return ( { })); }} /> +
+ + + Centered scrolling + +
}>