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 scroll jump when holding down arrow keys #15164

Merged
merged 2 commits into from
Oct 29, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ const GridVirtualScrollbar = React.forwardRef<HTMLDivElement, GridVirtualScrollb
return;
}

lastPosition.current = scroller[propertyScroll];

if (isLocked.current) {
isLocked.current = false;
return;
Expand All @@ -108,8 +110,6 @@ const GridVirtualScrollbar = React.forwardRef<HTMLDivElement, GridVirtualScrollb

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

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

const onScrollbarScroll = useEventCallback(() => {
Expand Down
26 changes: 3 additions & 23 deletions packages/x-data-grid/src/hooks/features/scroll/useGridScroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ export const useGridScroll = (
const logger = useGridLogger(apiRef, 'useGridScroll');
const colRef = apiRef.current.columnHeadersContainerRef;
const virtualScrollerRef = apiRef.current.virtualScrollerRef!;
const virtualScrollbarHorizontalRef = apiRef.current.virtualScrollbarHorizontalRef!;
const virtualScrollbarVerticalRef = apiRef.current.virtualScrollbarVerticalRef!;
const visibleSortedRows = useGridSelector(apiRef, gridExpandedSortedRowEntriesSelector);

const scrollToIndexes = React.useCallback<GridScrollApi['scrollToIndexes']>(
Expand Down Expand Up @@ -156,37 +154,19 @@ export const useGridScroll = (

const scroll = React.useCallback<GridScrollApi['scroll']>(
(params: Partial<GridScrollParams>) => {
if (
virtualScrollerRef.current &&
virtualScrollbarHorizontalRef.current &&
params.left !== undefined &&
colRef.current
) {
if (virtualScrollerRef.current && params.left !== undefined && colRef.current) {
const direction = isRtl ? -1 : 1;
colRef.current.scrollLeft = params.left;
virtualScrollerRef.current.scrollLeft = direction * params.left;
virtualScrollbarHorizontalRef.current.scrollLeft = direction * params.left;
logger.debug(`Scrolling left: ${params.left}`);
}
if (
virtualScrollerRef.current &&
virtualScrollbarVerticalRef.current &&
params.top !== undefined
) {
if (virtualScrollerRef.current && params.top !== undefined) {
virtualScrollerRef.current.scrollTop = params.top;
virtualScrollbarVerticalRef.current.scrollTop = params.top;
logger.debug(`Scrolling top: ${params.top}`);
}
logger.debug(`Scrolling, updating container, and viewport`);
},
[
virtualScrollerRef,
virtualScrollbarHorizontalRef,
virtualScrollbarVerticalRef,
isRtl,
colRef,
logger,
],
[virtualScrollerRef, isRtl, colRef, logger],
);

const getScrollPosition = React.useCallback<GridScrollApi['getScrollPosition']>(() => {
Expand Down
Loading