LiveBy / react-leaflet-control

Dumb React component for creating Controls
ISC License
88 stars 24 forks source link

Dragging does not work inside control #40

Closed ivangermanov closed 8 months ago

ivangermanov commented 4 years ago

I've discovered that due to

DomEvent.disableClickPropagation(_controlDiv);

anything inside the control using mouse dragging such as sliders and ranges inside the control do not fire. However, I've managed to find a workaround by replacing

onAdd(/* map */) {
  var _controlDiv = DomUtil.create("div", this.options.className);
  DomEvent.disableClickPropagation(_controlDiv);
  return _controlDiv;
},

with

onAdd(map) {
  var _controlDiv = DomUtil.create("div", this.options.className);
  DomEvent.on(_controlDiv, "mouseover touchstart", () => {
    map.dragging.disable();
  });
  DomEvent.on(_controlDiv, "mouseout touchend", () => {
    map.dragging.enable();
  });

  return _controlDiv;
},

Since we only care about the map not being moved when we're changing stuff inside the control, we can simply disable the map being dragged. This will not stop any events from propagating inside the control, so the aforementioned leaflet events should work both on mouse and touch devices.

Let me know what you think and if this is PR-worthy.