Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix scrolling by pixels #951

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading