From 26cc0abbcf476d46a51e5e20cd61e90d5e638602 Mon Sep 17 00:00:00 2001 From: Josh Kelley Date: Wed, 31 Aug 2022 23:27:48 -0400 Subject: [PATCH] Only drag zoom on left mouse button This makes drag act the same as pan (which is implemented by Hammer.js, which - as far as I can tell - automatically only listens to the left / primary mouse button). By default, right-click is intercepted by the browser to display a context menu, so this isn't noticeable, However, if `oncontextmenu` is used to disable that (e.g., to use JS to display a menu instead), then right-click can trigger zoom, which feels strange. --- src/handlers.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/handlers.js b/src/handlers.js index 00a90456..805f516c 100644 --- a/src/handlers.js +++ b/src/handlers.js @@ -52,7 +52,11 @@ function zoomStart(chart, event, zoomOptions) { export function mouseDown(chart, event) { const state = getState(chart); const {pan: panOptions, zoom: zoomOptions = {}} = state.options; - if (keyPressed(getModifierKey(panOptions), event) || keyNotPressed(getModifierKey(zoomOptions.drag), event)) { + if ( + event.button !== 0 || + keyPressed(getModifierKey(panOptions), event) || + keyNotPressed(getModifierKey(zoomOptions.drag), event) + ) { return call(zoomOptions.onZoomRejected, [{chart, event}]); }