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

Sets a default aria-label for interactive markers #11349

Merged
merged 6 commits into from
Dec 22, 2021
Merged
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
2 changes: 1 addition & 1 deletion src/ui/marker.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ export default class Marker extends Evented {
if (!options || !options.element) {
this._defaultMarker = true;
this._element = DOM.create('div');
this._element.setAttribute('aria-label', 'Map marker');

// create default map marker SVG
const defaultHeight = 41;
Expand Down Expand Up @@ -159,6 +158,7 @@ export default class Marker extends Evented {
this._offset = Point.convert(options && options.offset || [0, 0]);
}

if (!this._element.hasAttribute('aria-label')) this._element.setAttribute('aria-label', 'Map marker');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO "map marker" seems a bit verbose, "marker" alone should be sufficient. aria-label="map" already provides the context for the markers (although I guess that depends on #11038 to some degree).

this._element.classList.add('mapboxgl-marker');
this._element.addEventListener('dragstart', (e: DragEvent) => {
e.preventDefault();
Expand Down
15 changes: 15 additions & 0 deletions test/unit/ui/marker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,21 @@ test('Enter key on Marker opens a popup that was closed', (t) => {
t.end();
});

test('Interactive markers should have a default aria-label and a role attribute set to button', (t) => {
const map = createMap(t);
const element = window.document.createElement('div');
const marker = new Marker({color: "#FFFFFF", element})
.setLngLat([0, 0])
.addTo(map)
.setPopup(new Popup());

t.ok(marker.getElement().hasAttribute('aria-label'));
t.equal(marker.getElement().getAttribute('role'), 'button');

map.remove();
t.end();
});

test('Space key on Marker opens a popup that was closed', (t) => {
const map = createMap(t);
const marker = new Marker()
Expand Down