Skip to content

Commit

Permalink
Fix tooltip focus listener if getElement is no function (#8890)
Browse files Browse the repository at this point in the history
  • Loading branch information
Falke-Design committed May 18, 2023
1 parent 6e026b0 commit 8306fab
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions spec/suites/layer/TooltipSpec.js
Expand Up @@ -83,6 +83,16 @@ describe('Tooltip', function () {
expect(map.hasLayer(group._tooltip)).to.be(false);
});

it('opens on marker focus and ignore layers without getElement function', () => {
var marker1 = L.marker([41.18, 9.45]);
var someLayerWithoutGetElement = L.layerGroup();
var group = new L.FeatureGroup([marker1, someLayerWithoutGetElement]).addTo(map);
group.bindTooltip('Tooltip');
expect(function () {
happen.once(marker1.getElement(), {type:'focus'});
}).to.not.throwException();
});

it("is mentioned in aria-describedby of a bound layer", function () {
var layer = L.marker(center).addTo(map);

Expand Down
4 changes: 2 additions & 2 deletions src/layer/Tooltip.js
Expand Up @@ -393,7 +393,7 @@ Layer.include({
},

_addFocusListenersOnLayer: function (layer) {
var el = layer.getElement();
var el = typeof layer.getElement === 'function' && layer.getElement();
if (el) {
DomEvent.on(el, 'focus', function () {
this._tooltip._source = layer;
Expand All @@ -404,7 +404,7 @@ Layer.include({
},

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

0 comments on commit 8306fab

Please sign in to comment.