Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: only add ARIA-LABEL if the element does not already has one #5298

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
liorchamla marked this conversation as resolved.
Show resolved Hide resolved
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
Loading