diff --git a/packages/core/API.md b/packages/core/API.md index 44fb12bc4..eceb15362 100644 --- a/packages/core/API.md +++ b/packages/core/API.md @@ -417,7 +417,12 @@ scrollTo: ( row: number, dir?: "horizontal" | "vertical" | "both", paddingX?: number, - paddingY?: number + paddingY?: number, + options?: { + hAlign?: "start" | "center" | "end"; + vAlign?: "start" | "center" | "end"; + behavior?: ScrollBehavior; // "auto" | "smooth" | "instant" + } ) => void; ``` @@ -431,7 +436,11 @@ Requests the data grid to scroll to a particular location. If only one direction ## appendRow ```ts -appendRow: (col: number, openOverlay: boolean = true) => Promise; +appendRow: ( + col: number, + openOverlay: boolean = true, + behavior?: ScrollBehavior; // "auto" | "smooth" | "instant" +) => Promise; ``` Appends a row to the data grid. diff --git a/packages/core/src/data-editor/data-editor.tsx b/packages/core/src/data-editor/data-editor.tsx index 4736b1099..dce85ae68 100644 --- a/packages/core/src/data-editor/data-editor.tsx +++ b/packages/core/src/data-editor/data-editor.tsx @@ -687,6 +687,7 @@ type ScrollToFn = ( options?: { hAlign?: "start" | "center" | "end"; vAlign?: "start" | "center" | "end"; + behavior?: ScrollBehavior; } ) => void; @@ -697,7 +698,7 @@ export interface DataEditorRef { * @param col The column index to focus in the new row. * @returns A promise which waits for the append to complete. */ - appendRow: (col: number, openOverlay?: boolean) => Promise; + appendRow: (col: number, openOverlay?: boolean, behavior?: ScrollBehavior) => Promise; /** * Triggers cells to redraw. */ @@ -1608,10 +1609,11 @@ const DataEditorImpl: React.ForwardRefRenderFunction => { + async (col: number, openOverlay: boolean = true, behavior?: ScrollBehavior): Promise => { const c = mangledCols[col]; if (c?.trailingRowOptions?.disabled === true) { return; @@ -1664,7 +1666,7 @@ const DataEditorImpl: React.ForwardRefRenderFunction = p => { @@ -39,6 +40,7 @@ export const ImperativeScroll: React.VFC = p => { ref.current?.scrollTo(4, 99, "both", p.paddingX, p.paddingY, { vAlign: p.vAlign, hAlign: p.hAlign, + behavior: p.behavior, }); }; @@ -74,6 +76,7 @@ export const ImperativeScroll: React.VFC = p => { paddingX: 0, vAlign: "start", hAlign: "start", + behavior: "auto", }; (ImperativeScroll as any).argTypes = { paddingY: 0, @@ -86,4 +89,8 @@ export const ImperativeScroll: React.VFC = p => { control: { type: "select" }, options: ["start", "center", "end", undefined], }, + behavior: { + control: { type: "select" }, + options: ["smooth", "instant", "auto", undefined], + }, };