Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
liorchamla committed Jan 7, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 0061f85 commit 2ed3373
Showing 3 changed files with 17 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
10 changes: 10 additions & 0 deletions src/ui/marker.test.ts
Original file line number Diff line number Diff line change
@@ -258,8 +258,18 @@ describe('marker', () => {
const marker = new Marker().setLngLat([0, 0]).addTo(map);

expect(marker.getElement().getAttribute('aria-label')).toBe('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');
});


Check failure on line 272 in src/ui/marker.test.ts

GitHub Actions / Code Hygiene

More than 1 blank line not allowed
test('Marker anchor defaults to center', () => {
const map = createMap();
const marker = new Marker()
5 changes: 4 additions & 1 deletion src/ui/marker.ts
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit 2ed3373

Please sign in to comment.