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

Tooltip: make Map.openTooltip to consider interactive option #7531

Merged
merged 1 commit into from
Nov 1, 2021
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
8 changes: 8 additions & 0 deletions spec/suites/layer/TooltipSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,14 @@ describe('Tooltip', function () {
map.openTooltip('Tooltip', center);
});

it("map.openTooltip considers interactive option", function () {
if (!window.getComputedStyle) { this.skip(); } // IE9+

var tooltip = L.tooltip({interactive: true}).setContent('Tooltip');
map.openTooltip(tooltip, center);
expect(getComputedStyle(tooltip._container).pointerEvents).to.equal('auto');
});

it("can call closeTooltip while not on the map", function () {
var layer = new L.Marker(center);
layer.bindTooltip('Tooltip', {interactive: true});
Expand Down
25 changes: 14 additions & 11 deletions src/layer/Tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ export var Tooltip = DivOverlay.extend({
DivOverlay.prototype.onAdd.call(this, map);
this.setOpacity(this.options.opacity);

if (this.options.interactive) {
DomUtil.addClass(this._container, 'leaflet-clickable');
if (this._source) {
this._source.addInteractiveTarget(this._container);
}
}

// @namespace Map
// @section Tooltip events
// @event tooltipopen: TooltipEvent
Expand All @@ -88,6 +95,13 @@ export var Tooltip = DivOverlay.extend({
onRemove: function (map) {
DivOverlay.prototype.onRemove.call(this, map);

if (this.options.interactive) {
DomUtil.removeClass(this._container, 'leaflet-clickable');
if (this._source) {
this._source.removeInteractiveTarget(this._container);
}
}

// @namespace Map
// @section Tooltip events
// @event tooltipclose: TooltipEvent
Expand Down Expand Up @@ -330,13 +344,6 @@ Layer.include({

// open the tooltip on the map
this._map.openTooltip(this._tooltip, latlng);

// Tooltip container may not be defined if not permanent and never
// opened.
if (this._tooltip.options.interactive && this._tooltip._container) {
DomUtil.addClass(this._tooltip._container, 'leaflet-clickable');
this.addInteractiveTarget(this._tooltip._container);
}
}

return this;
Expand All @@ -347,10 +354,6 @@ Layer.include({
closeTooltip: function () {
if (this._tooltip) {
this._tooltip._close();
if (this._tooltip.options.interactive && this._tooltip._container) {
DomUtil.removeClass(this._tooltip._container, 'leaflet-clickable');
this.removeInteractiveTarget(this._tooltip._container);
}
}
return this;
},
Expand Down