Skip to content

zoom behaves incorrectly when dragging with right mouse button held down #5311

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
Argee88 opened this issue Dec 1, 2020 · 2 comments
Open
Labels
bug something broken P3 backlog

Comments

@Argee88
Copy link

Argee88 commented Dec 1, 2020

When having zoom enabled, I can use the left mouse button to drag a box around the area of interest and get a zoomed in version of my graph.

However, when I'm doing the exact same action with not the left mouse button held down, but the right mouse button held down there should not be any zoom applied. The current behaviour is, that I drag with the right mouse button held down, no box is drawn, but if I release the right mouse button there is zoom applied showing data within a distance of two units around the initially right-clicked point.

It is reproducible in this stackblitz.

Please feel free to ask, if you need any other details.

@secretwpn
Copy link

This produces unwanted behavior for my project as well and there doesn't seem to be any simple way to disable right mouse button interactions altogether

@simonapostolovski
Copy link

simonapostolovski commented Mar 12, 2024

A bit late, but I managed to fix this with a workaround for me.

boxRef is added on a wrapper of the graph, in my case a Box element from MUI that wraps the Plotly Graph

With this on right click drag does nothing, you can also add "click" event listener to further disable right click only (not drag)
The event on right click drag is blocked (stopped propagation) so that plotly internally doesn't fire the event.

For MouseEvent.button https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button

  const boxRef = useRef<HTMLDivElement>(null);

  useEffect(() => {
    const onMouseClickDragGraph = (ev: MouseEvent) => {
      // stop propagation if the button clicked/hold drag is different than the main (left click) mouse button
      if (ev.button !== 0) {
        ev.stopImmediatePropagation();
      }
    };

    let box: HTMLDivElement = null;

    if (boxRef && boxRef.current) {
      box = boxRef.current;
      box.addEventListener("mousedown", onMouseClickDragGraph);
      box.addEventListener("mouseup", onMouseClickDragGraph);
    }

    return () => {
      box?.removeEventListener("mousedown", onMouseClickDragGraph);
      box?.removeEventListener("mouseup", onMouseClickDragGraph);
    };
  }, []);

@gvwilson gvwilson self-assigned this Jul 12, 2024
@gvwilson gvwilson removed their assignment Aug 2, 2024
@gvwilson gvwilson changed the title Bug: Zoom behaviour when dragging with right mouse button held down zoom behaves incorrectly when dragging with right mouse button held down Aug 9, 2024
@gvwilson gvwilson added bug something broken P3 backlog labels Aug 9, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug something broken P3 backlog
Projects
None yet
Development

No branches or pull requests

4 participants