Merge pull request #5148 from xyflow/refactor/nowheel-pinch

Refactor/nowheel pinch
This commit is contained in:
Moritz Klack
2025-04-02 20:50:24 +02:00
committed by GitHub
2 changed files with 14 additions and 2 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@xyflow/system': patch
---
Prevent browser zoom for pinch zoom gestures on nowheel elements
@@ -141,10 +141,17 @@ export function createPanOnScrollHandler({
export function createZoomOnScrollHandler({ noWheelClassName, preventScrolling, d3ZoomHandler }: ZoomOnScrollParams) {
return function (this: Element, event: any, d: unknown) {
const isWheel = event.type === 'wheel';
// we still want to enable pinch zooming even if preventScrolling is set to false
const preventZoom = !preventScrolling && event.type === 'wheel' && !event.ctrlKey;
const preventZoom = !preventScrolling && isWheel && !event.ctrlKey;
const hasNoWheelClass = isWrappedWithClass(event, noWheelClassName);
if (preventZoom || isWrappedWithClass(event, noWheelClassName)) {
// if user is pinch zooming above a nowheel element, we don't want the browser to zoom
if (event.ctrlKey && isWheel && hasNoWheelClass) {
event.preventDefault();
}
if (preventZoom || hasNoWheelClass) {
return null;
}