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

Fix opening / closing tooltip while dragging map #7862

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions spec/suites/layer/TooltipSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,4 +343,47 @@ describe('Tooltip', function () {
expect(map.hasLayer(tooltip1)).to.not.be.ok();
expect(eventSpy.calledOnce).to.be.ok();
});

it("don't opens the tooltip on marker mouseover while dragging map", function () {
// Sometimes the mouse is moving faster then the map while dragging and then the marker can be hover and
// the tooltip opened / closed.
var layer = L.marker(center).addTo(map).bindTooltip('Tooltip');
var tooltip = layer.getTooltip();

// simulate map dragging
map.dragging.moving = function () {
return true;
};
happen.at('mouseover', 210, 195);
expect(tooltip.isOpen()).to.be(false);

// simulate map not dragging anymore
map.dragging.moving = function () {
return false;
};
happen.at('mouseover', 210, 195);
expect(tooltip.isOpen()).to.be.ok();
});

it("closes the tooltip on marker mouseout while dragging map and don't open it again", function () {
// Sometimes the mouse is moving faster then the map while dragging and then the marker can be hover and
// the tooltip opened / closed.
var layer = L.marker(center).addTo(map).bindTooltip('Tooltip');
var tooltip = layer.getTooltip();

// open tooltip before "dragging map"
happen.at('mouseover', 210, 195);
expect(tooltip.isOpen()).to.be.ok();

// simulate map dragging
map.dragging.moving = function () {
return true;
};
happen.mouseout(layer._icon, {relatedTarget: map._container});
expect(tooltip.isOpen()).to.be(false);

// tooltip should not open again while dragging
happen.at('mouseover', 210, 195);
expect(tooltip.isOpen()).to.be(false);
});
});
2 changes: 1 addition & 1 deletion src/layer/Tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ Layer.include({
},

_openTooltip: function (e) {
if (!this._tooltip || !this._map) {
if (!this._tooltip || !this._map || (this._map.dragging && this._map.dragging.moving())) {
return;
}
this._tooltip._source = e.layer || e.target;
Expand Down