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 4 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
1 change: 1 addition & 0 deletions src/ui/marker.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ export default class Marker extends Evented {
if (this._lngLat) this._popup.setLngLat(this._lngLat);

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

Choose a reason for hiding this comment

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

Since we're setting this attribute for the default marker in the constructor regardless of whether it's interactive or not, should we move this line to the constructor "else" block for consistency?

this._originalTabIndex = this._element.getAttribute('tabindex');
if (!this._originalTabIndex) {
this._element.setAttribute('tabindex', '0');
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