Skip to content

Commit

Permalink
Fix scrolling by pixels
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyll committed May 9, 2024
1 parent 3a97523 commit 6bed93f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/data-editor/data-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1496,8 +1496,8 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
height: 0,
};

let scrollX = 0;
let scrollY = 0;
let scrollX = desiredX ?? 0;
let scrollY = desiredY ?? 0;

if (trueCol !== undefined || trueRow !== undefined) {
targetRect = grid.getBounds((trueCol ?? 0) + rowMarkerOffset, trueRow ?? 0) ?? targetRect;
Expand Down
13 changes: 13 additions & 0 deletions packages/core/src/docs/examples/imperative-scroll.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ export const ImperativeScroll: React.VFC<ImperativeScrollProps> = p => {
});
};

const pixels = 1_000_000_000;
const onClickEnd = () => {
ref.current?.scrollTo({
amount: pixels,
unit: "px",
},
0,
"horizontal");
};

return (
<BeautifulWrapper
title="Imperative scrolling"
Expand All @@ -54,6 +64,9 @@ export const ImperativeScroll: React.VFC<ImperativeScrollProps> = p => {
<MoreInfo>
Click <button onClick={onClick}>Here</button> to scroll to column 4 row 100
</MoreInfo>
<MoreInfo>
Click <button onClick={onClickEnd}>Here</button> to scroll by {pixels} pixels
</MoreInfo>
</>
}>
<DataEditor
Expand Down

0 comments on commit 6bed93f

Please sign in to comment.