Skip to content

Commit

Permalink
Check if getElement() is undefined before adding focus listener (Ca…
Browse files Browse the repository at this point in the history
…nvas) (#8498)
  • Loading branch information
Falke-Design authored and mourner committed Oct 3, 2022
1 parent 00416a5 commit 579c90d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
12 changes: 12 additions & 0 deletions spec/suites/layer/vector/RectangleSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,16 @@ describe('Rectangle', function () {
expect(rectangle.getLatLngs()).to.eql(rectangle._latlngs);
});
});

describe("#Canvas", function () {
it("doesn't apply `focus` listener if element is undefined", function () {
map.remove();

map = L.map(container, {renderer: L.canvas()});
map.setView([0, 0], 6);
expect(function () {
L.polygon([[[2, 3], [4, 5]]]).addTo(map).bindTooltip('test');
}).to.not.throwException();
});
});
});
18 changes: 12 additions & 6 deletions src/layer/Tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,15 +387,21 @@ Layer.include({
},

_addFocusListenersOnLayer: function (layer) {
DomEvent.on(layer.getElement(), 'focus', function () {
this._tooltip._source = layer;
this.openTooltip();
}, this);
DomEvent.on(layer.getElement(), 'blur', this.closeTooltip, this);
var el = layer.getElement();
if (el) {
DomEvent.on(el, 'focus', function () {
this._tooltip._source = layer;
this.openTooltip();
}, this);
DomEvent.on(el, 'blur', this.closeTooltip, this);
}
},

_setAriaDescribedByOnLayer: function (layer) {
layer.getElement().setAttribute('aria-describedby', this._tooltip._container.id);
var el = layer.getElement();
if (el) {
el.setAttribute('aria-describedby', this._tooltip._container.id);
}
},


Expand Down

0 comments on commit 579c90d

Please sign in to comment.