Skip to content

Commit

Permalink
Only drag zoom on left mouse button
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
joshkel committed Sep 1, 2022
1 parent 5849dda commit dd07f8e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/handlers.js
Expand Up @@ -52,8 +52,12 @@ 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)) {
return call(zoomOptions.onZoomRejected, [{chart, event}]);
if (
event.button !== 0 ||
keyPressed(getModifierKey(panOptions), event) ||
keyNotPressed(getModifierKey(zoomOptions.drag), event)
) {
return call(zoomOptions.onZoomRejected, [{ chart, event }]);
}

if (zoomStart(chart, event, zoomOptions) === false) {
Expand Down

0 comments on commit dd07f8e

Please sign in to comment.