Skip to content

Gesture Toggles

The gestures option lets you toggle individual gesture types on or off. This is useful when you need only a subset of interactions — for example, a read-only map that zooms but doesn’t pan, or an image rotation tool.

// Equivalent to:
useZoomPinch({
containerRef,
gestures: { pan: true, zoom: true, rotate: false },
})

Pan and zoom are enabled by default. Rotation is disabled.

useZoomPinch({
containerRef,
gestures: { pan: false },
})
useZoomPinch({
containerRef,
gestures: { zoom: false },
})
useZoomPinch({
containerRef,
gestures: { pan: false, zoom: false, rotate: true },
})
useZoomPinch({
containerRef,
gestures: { rotate: true },
})
ToggleGesture inputs affected
panMouse wheel scroll, trackpad two-finger scroll, pointer drag
zoomCtrl+wheel, trackpad pinch, multi-touch pinch distance
rotateMulti-touch pinch angle (two-finger twist)

Gesture toggles only control user input. Programmatic methods always work:

const { panTo, zoomIn, rotateTo } = useZoomPinch({
containerRef,
gestures: { pan: false, zoom: false, rotate: false },
})
// All of these still work:
panTo(100, 200, { animate: true })
zoomIn(2, { animate: true })
rotateTo(45, { animate: true })
  • enabled: false — disables all gesture handling (master switch)
  • gestures: { pan: false } — disables only pan gestures, zoom still works
// Nothing works — no gestures at all
useZoomPinch({ containerRef, enabled: false })
// Zoom works, pan doesn't
useZoomPinch({ containerRef, gestures: { pan: false } })

Since gestures is a regular prop, you can toggle gestures at runtime:

const [mode, setMode] = useState<"pan" | "rotate">("pan")
useZoomPinch({
containerRef,
gestures: {
pan: mode === "pan",
rotate: mode === "rotate",
},
})
// Toggle between modes
<button onClick={() => setMode(mode === "pan" ? "rotate" : "pan")}>
Switch to {mode === "pan" ? "Rotate" : "Pan"} mode
</button>