Set alt HTML attribute only for img-based Markers (#5979)

carto
Michael Siadak 7 years ago committed by Vladimir Agafonkin
parent fa40fa3a48
commit f31e39c1ac

@ -190,6 +190,21 @@ describe("Marker", function () {
expect(marker._icon.parentNode).to.be(map._panes.markerPane);
expect(marker._shadow.parentNode).to.be(map._panes.shadowPane);
});
it("sets the alt attribute to an empty string when no alt text is passed", function () {
var marker = L.marker([0, 0], {icon: icon1});
map.addLayer(marker);
var icon = marker._icon;
expect(icon.hasAttribute('alt')).to.be(true);
expect(icon.alt).to.be('');
});
it("doesn't set the alt attribute for DivIcons", function () {
var marker = L.marker([0, 0], {icon: L.divIcon(), alt: 'test'});
map.addLayer(marker);
var icon = marker._icon;
expect(icon.hasAttribute('alt')).to.be(false);
});
});
describe("#setLatLng", function () {

@ -203,8 +203,9 @@ export var Marker = Layer.extend({
if (options.title) {
icon.title = options.title;
}
if (options.alt) {
icon.alt = options.alt;
if (icon.tagName === 'IMG') {
icon.alt = options.alt || '';
}
}

Loading…
Cancel
Save