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

This commit is contained in:
Michael Siadak 2018-01-01 02:30:16 -07:00 committed by Vladimir Agafonkin
parent fa40fa3a48
commit f31e39c1ac
2 changed files with 18 additions and 2 deletions

View File

@ -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 () {

View File

@ -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 || '';
}
}