Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Click on Popup trigger on map click event #725

Closed
akiirii opened this issue May 3, 2019 · 5 comments · Fixed by #753
Closed

Click on Popup trigger on map click event #725

akiirii opened this issue May 3, 2019 · 5 comments · Fixed by #753

Comments

@akiirii
Copy link

akiirii commented May 3, 2019

Last update 4.3.0 (probably "Fixed mouse events on Marker and Cluster elements") occurred problem with popups, because click on Popup trigger on map click event, also it is possible to drag map by clicking on popup

It is really problematic when you fire hide popup action after clicking on map.

In previous library version everything is ok.

@mklopets
Copy link
Collaborator

I'm not sure what the "correct" behaviour would be here. I suppose the popup click handler's stopPropagation should stop propagation to the map – not sure why it's not the case right now.

One option to solve your problem in the meanwhile would be to change your code that closes the popup. Inside the click handler, add an extra check:

map.on('click', (e) => {
  const { target } = e.originalEvent;
  const canvas = map.getCanvas();
  const shouldClosePopup = target === canvas;
  console.log('shouldClosePopup', shouldClosePopup);
});

shouldClosePopup will be false if the original mouse event's target was something else, e.g a popover.

@akiirii
Copy link
Author

akiirii commented May 10, 2019

yeah, but it is only kind of work around, and also don't fix all of problems.
It is not only click, but also hover and drag, if you try copy text you actually drag map, cursor doesn't change etc

@mklopets
Copy link
Collaborator

I can also think of valid use cases where the popover should remain open and the map draggable when dragging on top of it. Still not sure if this is really a bug. Before v4.3.0, there was definitely a bug with markers, at least.

@redbmk
Copy link
Contributor

redbmk commented May 10, 2019

I would say this isn’t necessarily unintended behavior, but it is a breaking change. Maybe the marker fix really should have gone to v5? Or maybe popups are a special case. What if popups have an option to prevent mouse events propagating to the map and its on by default to avoid a breaking change (e.g. 4.3.1 would go back to previous behavior with an option to pass events through)?

mklopets added a commit to mklopets/react-mapbox-gl that referenced this issue Jul 14, 2019
layers

This flag defaulting to `false` brings back the default behaviour from
prior to v4.3.0.

Fixes alex3165#725
@mklopets
Copy link
Collaborator

mklopets commented Jul 14, 2019

Released v4.5.0 which changes the default behaviour back to the "old way".

For cross-referencing, this is a dupe of #733

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants