mirror of
https://github.com/Leaflet/Leaflet.git
synced 2025-08-20 14:34:38 +00:00
Check if getElement()
is undefined before adding focus listener (Canvas) (#8498)
This commit is contained in:

committed by
Vladimir Agafonkin

parent
00416a546f
commit
579c90d271
@ -110,4 +110,16 @@ describe('Rectangle', function () {
|
|||||||
expect(rectangle.getLatLngs()).to.eql(rectangle._latlngs);
|
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();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -387,15 +387,21 @@ Layer.include({
|
|||||||
},
|
},
|
||||||
|
|
||||||
_addFocusListenersOnLayer: function (layer) {
|
_addFocusListenersOnLayer: function (layer) {
|
||||||
DomEvent.on(layer.getElement(), 'focus', function () {
|
var el = layer.getElement();
|
||||||
|
if (el) {
|
||||||
|
DomEvent.on(el, 'focus', function () {
|
||||||
this._tooltip._source = layer;
|
this._tooltip._source = layer;
|
||||||
this.openTooltip();
|
this.openTooltip();
|
||||||
}, this);
|
}, this);
|
||||||
DomEvent.on(layer.getElement(), 'blur', this.closeTooltip, this);
|
DomEvent.on(el, 'blur', this.closeTooltip, this);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
_setAriaDescribedByOnLayer: function (layer) {
|
_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);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user