Skip to content

Commit

Permalink
Fix indicator jumping when scrolling table with keyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Polleps committed Jul 17, 2024
1 parent 0b516b2 commit d8a839f
Showing 1 changed file with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@ import {
import { scrollIntoView } from './helpers/scrollIntoView';
import { CursorMode, useTableEditorContext } from './TableEditorContext';

type OnScrollCallbackOptions = {
scrollUpdateWasRequested: boolean;
};

export interface ActiveCellIndicatorProps {
sizeStr: string;
scrollerRef: React.RefObject<HTMLDivElement>;
setOnScroll: (onScroll: () => void) => void;
setOnScroll: (
onScroll: ({ scrollUpdateWasRequested }: OnScrollCallbackOptions) => void,
) => void;
}

const cursorGoesOffscreen = (parentRect: DOMRect, childRect: DOMRect) => {
Expand Down Expand Up @@ -128,14 +134,17 @@ export function ActiveCellIndicator({
);

useEffect(() => {
setOnScroll(() => (_, __, requested: boolean) => {
if (requested) {
return;
}

setScrolling(true);
updatePosition(false);
});
setOnScroll(
() =>
({ scrollUpdateWasRequested }: OnScrollCallbackOptions) => {
if (scrollUpdateWasRequested) {
return;
}

setScrolling(true);
updatePosition(false);
},
);
}, [updatePosition]);

useEffect(() => {
Expand Down

0 comments on commit d8a839f

Please sign in to comment.