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

[DataGrid] Fix scrollbar position not being updated after scrollToIndexes #14877

Merged
merged 1 commit into from
Oct 8, 2024
Merged
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arminmeh I just noticed that this PR introduced a regression: https://deploy-preview-14877--material-ui-x.netlify.app/x/react-data-grid/#premium-plan

Screen.Recording.2024-10-08.at.22.09.55.mov

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take a look

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ const GridVirtualScrollbar = React.forwardRef<HTMLDivElement, GridVirtualScrollb
function GridVirtualScrollbar(props, ref) {
const apiRef = useGridPrivateApiContext();
const rootProps = useGridRootProps();
const isLocked = React.useRef(false);
const lastPosition = React.useRef(0);
const lastPositionScroller = React.useRef(0);
const lastPositionScrollbar = React.useRef(0);
const scrollbarRef = React.useRef<HTMLDivElement>(null);
const contentRef = React.useRef<HTMLDivElement>(null);
const classes = useUtilityClasses(rootProps, props.position);
Expand All @@ -96,34 +96,28 @@ const GridVirtualScrollbar = React.forwardRef<HTMLDivElement, GridVirtualScrollb
const scroller = apiRef.current.virtualScrollerRef.current!;
const scrollbar = scrollbarRef.current!;

if (scroller[propertyScroll] === lastPosition.current) {
if (scroller[propertyScroll] === lastPositionScroller.current) {
return;
}

if (isLocked.current) {
isLocked.current = false;
return;
}
isLocked.current = true;

const value = scroller[propertyScroll] / contentSize;
scrollbar[propertyScroll] = value * scrollbarInnerSize;

lastPosition.current = scroller[propertyScroll];
lastPositionScrollbar.current = scrollbar[propertyScroll];
});

const onScrollbarScroll = useEventCallback(() => {
const scroller = apiRef.current.virtualScrollerRef.current!;
const scrollbar = scrollbarRef.current!;

if (isLocked.current) {
isLocked.current = false;
if (scrollbar[propertyScroll] === lastPositionScrollbar.current) {
return;
}
isLocked.current = true;

const value = scrollbar[propertyScroll] / scrollbarInnerSize;
scroller[propertyScroll] = value * contentSize;

lastPositionScroller.current = scroller[propertyScroll];
});

useOnMount(() => {
Expand Down