Skip to content
This repository was archived by the owner on Aug 5, 2025. It is now read-only.

Commit ef66588

Browse files
anisometropieemersion
authored andcommitted
ui-charts: disable scroll and zooming while drawing zoom rectangle
Signed-off-by: Valentin Chanas <[email protected]>
1 parent 5a4ad4b commit ef66588

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

ui-charts/src/manchette/hooks/useManchetteWithSpaceTimeChart.tsx

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -296,14 +296,21 @@ const useManchetteWithSpaceTimeChart = ({
296296
setState((prev) => ({ ...prev, yZoom: 1 }));
297297
}, []);
298298

299-
const handleScroll = useCallback(() => {
300-
if (!isShiftPressed && manchetteWithSpaceTimeChartRef.current) {
301-
const { scrollTop } = manchetteWithSpaceTimeChartRef.current;
302-
if (scrollTop || scrollTop === 0) {
303-
setState((prev) => ({ ...prev, yOffset: scrollTop }));
299+
const handleScroll = useCallback(
300+
(e: React.UIEvent<HTMLDivElement>) => {
301+
if (rect) {
302+
e.preventDefault();
303+
return;
304304
}
305-
}
306-
}, [isShiftPressed, manchetteWithSpaceTimeChartRef]);
305+
if (!isShiftPressed && manchetteWithSpaceTimeChartRef.current) {
306+
const { scrollTop } = manchetteWithSpaceTimeChartRef.current;
307+
if (scrollTop || scrollTop === 0) {
308+
setState((prev) => ({ ...prev, yOffset: scrollTop }));
309+
}
310+
}
311+
},
312+
[isShiftPressed, manchetteWithSpaceTimeChartRef, rect]
313+
);
307314

308315
const handleKeyDown = useCallback((event: KeyboardEvent) => {
309316
if (event.key === 'Shift') {
@@ -527,7 +534,7 @@ const useManchetteWithSpaceTimeChart = ({
527534
return useMemo<{
528535
manchetteProps: ManchetteProps;
529536
spaceTimeChartProps: SpaceTimeChartProps;
530-
handleScroll: () => void;
537+
handleScroll: (e: React.UIEvent<HTMLDivElement>) => void;
531538
handleXZoom: (newXZoom: number, xPosition?: number) => void;
532539
xZoom: number;
533540
toggleZoomMode: () => void;
@@ -565,7 +572,7 @@ const useManchetteWithSpaceTimeChart = ({
565572
delta,
566573
position,
567574
}: Parameters<NonNullable<SpaceTimeChartProps['onZoom']>>[0]) => {
568-
if (isShiftPressed) {
575+
if (isShiftPressed && !rect) {
569576
handleXZoom(xZoom + delta, position.x);
570577
}
571578
},

0 commit comments

Comments
 (0)