Skip to content

Commit 6ec8bc9

Browse files
ben-lu-uwMalvoz
andauthored
Add attribution for keyboard shortcuts (#683)
* Add attribution for keyboard shortcuts * Modularize the attribution control code * Add kbdAttribution.test.js * Add accessible name to close button Co-authored-by: Robert Linder <[email protected]> * Localize keyboard shortcut attribution button Co-authored-by: Robert Linder <[email protected]>
1 parent c535209 commit 6ec8bc9

File tree

7 files changed

+79
-7
lines changed

7 files changed

+79
-7
lines changed

src/mapml-viewer.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,7 @@ export class MapViewer extends HTMLElement {
213213
});
214214
this._addToHistory();
215215
// the attribution control is not optional
216-
this._attributionControl = this._map.attributionControl.setPrefix('<a href="https://www.w3.org/community/maps4html/" title="W3C Maps for HTML Community Group">Maps4HTML</a> | <img src="data:image/svg+xml;base64,PHN2ZyBhcmlhLWhpZGRlbj0idHJ1ZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB3aWR0aD0iMTIiIGhlaWdodD0iOCI+PHBhdGggZmlsbD0iIzRDN0JFMSIgZD0iTTAgMGgxMnY0SDB6Ii8+PHBhdGggZmlsbD0iI0ZGRDUwMCIgZD0iTTAgNGgxMnYzSDB6Ii8+PHBhdGggZmlsbD0iI0UwQkMwMCIgZD0iTTAgN2gxMnYxSDB6Ii8+PC9zdmc+" style="padding-right: 0.3em;" alt="Slava Ukraini"> <a href="https://leafletjs.com" title="A JS library for interactive maps">Leaflet</a>');
217-
this._attributionControl.getContainer().setAttribute("role","group");
218-
this._attributionControl.getContainer().setAttribute("aria-label","Map data attribution");
216+
M.attributionControl(this);
219217

220218
this.setControls(false,false,true);
221219
this._crosshair = M.crosshair().addTo(this._map);

src/mapml.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,7 @@ label.mapml-layer-item-toggle {
860860
padding-right: 5px;
861861
}
862862

863+
.shortcuts-dialog > ul > li > kbd,
863864
.mapml-feature-index-content > span > kbd{
864865
background-color: lightgrey;
865866
padding-right: 4px;
@@ -877,3 +878,11 @@ label.mapml-layer-item-toggle {
877878
width: 1px;
878879
}
879880

881+
.shortcuts-dialog > button{
882+
font-size: inherit;
883+
}
884+
885+
.shortcuts-dialog > ul {
886+
padding: 0;
887+
list-style-type:none;
888+
}

src/mapml/control/AttributionControl.js

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/mapml/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import { ContextMenu } from './handlers/ContextMenu';
5353
import { Util } from './utils/Util';
5454
import { ReloadButton, reloadButton } from './control/ReloadButton';
5555
import { FullscreenButton, fullscreenButton } from './control/FullscreenButton';
56+
import {attributionControl} from "./control/AttributionControl";
5657
import { Crosshair, crosshair } from "./layers/Crosshair";
5758
import { Feature, feature } from "./features/feature";
5859
import { FeatureRenderer, featureRenderer } from './features/featureRenderer';
@@ -647,6 +648,8 @@ M.reloadButton = reloadButton;
647648
M.FullscreenButton = FullscreenButton;
648649
M.fullscreenButton = fullscreenButton;
649650

651+
M.attributionControl = attributionControl;
652+
650653
M.MapMLStaticTileLayer = MapMLStaticTileLayer;
651654
M.mapMLStaticTileLayer = mapMLStaticTileLayer;
652655

src/mapml/options.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@ export var Options = {
2727
amEastBound: "Reached east bound, panning east disabled",
2828
amWestBound: "Reached west bound, panning west disabled",
2929
amNorthBound: "Reached north bound, panning north disabled",
30-
amSouthBound: "Reached south bound, panning south disabled"
30+
amSouthBound: "Reached south bound, panning south disabled",
31+
kbdShortcuts: "Keyboard shortcuts",
32+
kbdMovement: "Movement keys",
33+
kbdFeature: "Feature navigation keys",
34+
kbdPanUp: "Pan up",
35+
kbdPanDown: "Pan down",
36+
kbdPanLeft: "Pan left",
37+
kbdPanRight: "Pan right",
38+
kbdPanIncrement: "pan increment",
39+
kbdZoom: "Zoom in/out 3 levels",
40+
kbdPrevFeature: "Previous feature",
41+
kbdNextFeature: "Next feature",
3142
}
3243
};

src/web-map.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,7 @@ export class WebMap extends HTMLMapElement {
228228
});
229229
this._addToHistory();
230230
// the attribution control is not optional
231-
this._attributionControl = this._map.attributionControl.setPrefix('<a href="https://www.w3.org/community/maps4html/" title="W3C Maps for HTML Community Group">Maps4HTML</a> | <img src="data:image/svg+xml;base64,PHN2ZyBhcmlhLWhpZGRlbj0idHJ1ZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB3aWR0aD0iMTIiIGhlaWdodD0iOCI+PHBhdGggZmlsbD0iIzRDN0JFMSIgZD0iTTAgMGgxMnY0SDB6Ii8+PHBhdGggZmlsbD0iI0ZGRDUwMCIgZD0iTTAgNGgxMnYzSDB6Ii8+PHBhdGggZmlsbD0iI0UwQkMwMCIgZD0iTTAgN2gxMnYxSDB6Ii8+PC9zdmc+" style="padding-right: 0.3em;" alt="Slava Ukraini"><a href="https://leafletjs.com" title="A JS library for interactive maps">Leaflet</a>');
232-
this._attributionControl.getContainer().setAttribute("role","group");
233-
this._attributionControl.getContainer().setAttribute("aria-label","Map data attribution");
231+
M.attributionControl(this);
234232

235233
this.setControls(false,false,true);
236234
this._crosshair = M.crosshair().addTo(this._map);
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { test, expect, chromium } from '@playwright/test';
2+
3+
test.describe("Keyboard shortcut attribution test", ()=> {
4+
let page;
5+
let context;
6+
test.beforeAll(async () => {
7+
context = await chromium.launchPersistentContext('');
8+
page = context.pages().find((page) => page.url() === 'about:blank') || await context.newPage();
9+
await page.goto("mapml-viewer.html");
10+
});
11+
12+
test.afterAll(async function () {
13+
await context.close();
14+
});
15+
16+
test("Keyboard shortcuts attribution opens up dialog", async () => {
17+
for(let i = 0; i < 7; i++) {
18+
await page.keyboard.press("Tab");
19+
}
20+
21+
await page.keyboard.press("Enter");
22+
const dialog = await page.$eval("body > mapml-viewer div > dialog",
23+
(dialog) => dialog.hasAttribute("open")
24+
);
25+
26+
expect(dialog).toBe(true);
27+
});
28+
29+
test("X button closes dialog", async () => {
30+
await page.keyboard.press("Enter");
31+
const dialog = await page.$eval("body > mapml-viewer div > dialog",
32+
(dialog) => dialog.hasAttribute("open")
33+
);
34+
expect(dialog).toBe(false);
35+
});
36+
});

0 commit comments

Comments
 (0)