Skip to content

Commit 3f9ff07

Browse files
authored
mobile scroll prevention (#93)
1 parent 3dfcd07 commit 3f9ff07

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@weng-lab/psychscreen-ui-components",
33
"description": "Typescript and Material UI based components used for psychSCREEN",
44
"author": "SCREEN Team @ UMass Chan Medical School",
5-
"version": "2.0.24",
5+
"version": "2.0.25",
66
"license": "MIT",
77
"type": "module",
88
"typings": "dist/index.d.ts",

src/components/ScatterPlot/scatterplot.tsx

+17-4
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,33 @@ const ScatterPlot = <T extends object, S extends boolean | undefined = undefined
7474

7575
useEffect(() => {
7676
const graphElement = graphRef.current;
77-
77+
7878
const handleWheel = (event: WheelEvent) => {
79-
// Prevent default scroll behavior when using the wheel in the graph
80-
event.preventDefault();
79+
event.preventDefault(); //prevent scrolling using wheel
80+
};
81+
82+
const handleTouchMove = (event: TouchEvent) => {
83+
event.preventDefault(); // Prevent scrolling during any touch movement
84+
};
85+
86+
const handleTouchStart = (event: TouchEvent) => {
87+
event.preventDefault(); // Prevent scrolling on touch start
8188
};
89+
8290
if (graphElement) {
8391
graphElement.addEventListener('wheel', handleWheel, { passive: false });
92+
graphElement.addEventListener('touchstart', handleTouchStart, { passive: false });
93+
graphElement.addEventListener('touchmove', handleTouchMove, { passive: false });
8494
}
95+
8596
return () => {
8697
if (graphElement) {
8798
graphElement.removeEventListener('wheel', handleWheel);
99+
graphElement.removeEventListener('touchstart', handleTouchStart);
100+
graphElement.removeEventListener('touchmove', handleTouchMove);
88101
}
89102
};
90-
}, [graphRef]);
103+
}, [graphRef]);
91104

92105
const handleSelectionModeChange = (mode: "select" | "pan" | "none") => {
93106
setSelectMode(mode);

0 commit comments

Comments
 (0)