Skip to content

Commit

Permalink
feat(marker.ts): only add aria-label if the custom element does not a…
Browse files Browse the repository at this point in the history
…lready has one
  • Loading branch information
liorchamla committed Jan 7, 2025
1 parent 0061f85 commit 1594e62
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
## main

### ✨ Features and improvements

- Now only adds `aria-label` on the Marker's element if it does not already has one ([#5298](https://github.com/maplibre/maplibre-gl-js/pull/5298))

- _...Add new stuff here..._

### 🐞 Bug fixes
Expand Down
12 changes: 12 additions & 0 deletions src/ui/marker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,18 @@ describe('marker', () => {
expect(marker.getElement().getAttribute('aria-label')).toBe('alt title');
});

test('Marker aria-label is not set if the element already has one', () => {
const map = createMap({locale: {'Marker.Title': 'alt title'}});
const customHtmlElement = document.createElement('div');
customHtmlElement.setAttribute('aria-label', 'custom aria label');

const markerWithHtmlElement = new Marker({
element: customHtmlElement
}).setLngLat([10, 10]).addTo(map);

expect(markerWithHtmlElement.getElement().getAttribute('aria-label')).toBe('custom aria label');
});

test('Marker anchor defaults to center', () => {
const map = createMap();
const marker = new Marker()
Expand Down
5 changes: 4 additions & 1 deletion src/ui/marker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,10 @@ export class Marker extends Evented {
addTo(map: Map): this {
this.remove();
this._map = map;
this._element.setAttribute('aria-label', map._getUIString('Marker.Title'));

if (!this._element.hasAttribute('aria-label')) {
this._element.setAttribute('aria-label', map._getUIString('Marker.Title'));
}

map.getCanvasContainer().appendChild(this._element);
map.on('move', this._update);
Expand Down

0 comments on commit 1594e62

Please sign in to comment.