Skip to content

Commit 7c743d7

Browse files
authored
Change introduced <a> controls to use <button> (#488)
* Add generic `mapml-button` class * Change context menu items from `<a>` to `<button>` * Change `mapml-reload-button` from `<a>` to `<button>` * Change `mapml-popup-button` from `<a>` to `<button>` * Change `mapml-layer-remove-button` from `<a>` to `<button>` * Correct comment in Focus Controls test
1 parent c442573 commit 7c743d7

File tree

11 files changed

+98
-65
lines changed

11 files changed

+98
-65
lines changed

src/mapml.css

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,25 @@
4646
* Controls.
4747
*/
4848

49+
/* Generic class for seamless buttons */
50+
.mapml-button {
51+
background-color: transparent;
52+
border: none;
53+
border-radius: 0;
54+
color: inherit;
55+
font: inherit;
56+
line-height: inherit;
57+
margin: 0;
58+
padding: 0;
59+
overflow: hidden;
60+
text-align: left;
61+
text-align: inline-start;
62+
text-transform: none;
63+
-webkit-appearance: none;
64+
-moz-appearance: none;
65+
appearance: none;
66+
}
67+
4968
.leaflet-top .leaflet-control {
5069
margin-top: 5px;
5170
}
@@ -54,13 +73,25 @@
5473
margin-left: 5px;
5574
}
5675

57-
.leaflet-bar a {
76+
.leaflet-bar a,
77+
.mapml-reload-button {
78+
background-color: #fff;
5879
box-sizing: border-box;
5980
width: 44px !important;
6081
height: 44px !important;
6182
line-height: 44px !important;
6283
font-size: 34px !important;
6384
font-weight: normal;
85+
text-align: center;
86+
}
87+
88+
.mapml-reload-button:not([aria-disabled="true"]):hover {
89+
background-color: #f4f4f4;
90+
}
91+
92+
.mapml-reload-button[aria-disabled="true"] {
93+
color: #bbb;
94+
cursor: default;
6495
}
6596

6697
.leaflet-control-layers-toggle {
@@ -69,11 +100,13 @@
69100
}
70101

71102
.leaflet-bar a,
72-
.leaflet-control-layers {
103+
.leaflet-control-layers,
104+
.mapml-reload-button {
73105
border-color: #e3e3e3 !important;
74106
}
75107

76-
.leaflet-control-layers {
108+
.leaflet-control-layers,
109+
.mapml-reload-button {
77110
border-radius: 4px !important;
78111
}
79112
.leaflet-touch .leaflet-bar a:last-child {
@@ -226,7 +259,7 @@
226259
cursor: default;
227260
}
228261

229-
.mapml-contextmenu a.mapml-contextmenu-item {
262+
.mapml-contextmenu button.mapml-contextmenu-item {
230263
display: block;
231264
color: #222;
232265
font-size: 12px;
@@ -236,9 +269,10 @@
236269
border-top: 1px solid transparent;
237270
border-bottom: 1px solid transparent;
238271
cursor: default;
272+
width: 100%;
239273
}
240274

241-
.mapml-contextmenu a.mapml-contextmenu-item.over {
275+
.mapml-contextmenu button.mapml-contextmenu-item.over {
242276
background-color: #f4f4f4;
243277
border-top: 1px solid #f0f0f0;
244278
border-bottom: 1px solid #f0f0f0;
@@ -448,6 +482,10 @@ summary {
448482
font-weight: bold;
449483
background: transparent;
450484
white-space: nowrap;
485+
box-sizing: border-box;
486+
width: 44px;
487+
height: 44px;
488+
line-height: 44px;
451489
}
452490

453491
.mapml-focus-buttons {
@@ -461,7 +499,7 @@ summary {
461499
padding: 2px;
462500
}
463501

464-
.mapml-focus-buttons a,
502+
.mapml-focus-buttons button,
465503
.leaflet-container a.leaflet-popup-close-button {
466504
width: 44px;
467505
height: 44px;
@@ -480,7 +518,7 @@ summary {
480518
display: block;
481519
text-align: center;
482520
}
483-
.mapml-focus-buttons a {
521+
.mapml-focus-buttons button {
484522
display: inline-block;
485523
padding: 0;
486524
}

src/mapml/control/ReloadButton.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ export var ReloadButton = L.Control.extend({
66
onAdd: function (map) {
77
let container = L.DomUtil.create("div", "mapml-reload-button leaflet-bar");
88

9-
let link = L.DomUtil.create("a", "mapml-reload-button", container);
10-
link.innerHTML = "&#x021BA";
11-
link.href = "#";
9+
let link = L.DomUtil.create("button", "mapml-reload-button", container);
10+
link.innerHTML = "<span aria-hidden='true'>&#x021BA</span>";
1211
link.title = "Reload";
13-
link.setAttribute('role', 'button');
12+
link.setAttribute("type", "button");
13+
link.classList.add("mapml-button");
1414
link.setAttribute('aria-label', "Reload");
1515

1616
L.DomEvent.disableClickPropagation(link);

src/mapml/handlers/ContextMenu.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,13 +324,13 @@ export var ContextMenu = L.Handler.extend({
324324
}
325325

326326
var itemCls = 'mapml-contextmenu-item',
327-
el = this._insertElementAt('a', itemCls, container, index),
327+
el = this._insertElementAt('button', itemCls, container, index),
328328
callback = this._createEventHandler(el, options.callback, options.context, options.hideOnSelect),
329329
html = '';
330330

331331
el.innerHTML = html + options.text;
332-
el.href = "#";
333-
el.setAttribute("role","button");
332+
el.setAttribute("type", "button");
333+
el.classList.add("mapml-button");
334334
if(options.popup){
335335
el.setAttribute("aria-haspopup", "true");
336336
el.setAttribute("aria-expanded", "false");

src/mapml/layers/MapLayer.js

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -497,12 +497,11 @@ export var MapMLLayer = L.Layer.extend({
497497

498498
summaryContainer.classList.add('mapml-control-summary-container');
499499

500-
let removeButton = document.createElement('a');
501-
removeButton.href = '#';
502-
removeButton.role = 'button';
500+
let removeButton = document.createElement('button');
501+
removeButton.type = 'button';
503502
removeButton.title = 'Remove Layer';
504503
removeButton.innerHTML = "<span aria-hidden='true'>&#10006;</span>";
505-
removeButton.classList.add('mapml-layer-remove-button');
504+
removeButton.classList.add('mapml-layer-remove-button', 'mapml-button');
506505
L.DomEvent.disableClickPropagation(removeButton);
507506
L.DomEvent.on(removeButton, 'click', L.DomEvent.stop);
508507
L.DomEvent.on(removeButton, 'click', (e)=>{
@@ -1203,9 +1202,8 @@ export var MapMLLayer = L.Layer.extend({
12031202
let div = L.DomUtil.create("nav", "mapml-focus-buttons");
12041203

12051204
// creates |< button, focuses map
1206-
let mapFocusButton = L.DomUtil.create('a',"mapml-popup-button", div);
1207-
mapFocusButton.href = '#';
1208-
mapFocusButton.role = "button";
1205+
let mapFocusButton = L.DomUtil.create("button", "mapml-popup-button", div);
1206+
mapFocusButton.type = "button";
12091207
mapFocusButton.title = "Focus Map";
12101208
mapFocusButton.innerHTML = "<span aria-hidden='true'>|&#10094;</span>";
12111209
L.DomEvent.disableClickPropagation(mapFocusButton);
@@ -1216,9 +1214,8 @@ export var MapMLLayer = L.Layer.extend({
12161214
}, popup);
12171215

12181216
// creates < button, focuses previous feature, if none exists focuses the current feature
1219-
let previousButton = L.DomUtil.create('a', "mapml-popup-button", div);
1220-
previousButton.href = '#';
1221-
previousButton.role = "button";
1217+
let previousButton = L.DomUtil.create("button", "mapml-popup-button", div);
1218+
previousButton.type = "button";
12221219
previousButton.title = "Previous Feature";
12231220
previousButton.innerHTML = "<span aria-hidden='true'>&#10094;</span>";
12241221
L.DomEvent.disableClickPropagation(previousButton);
@@ -1231,19 +1228,17 @@ export var MapMLLayer = L.Layer.extend({
12311228
featureCount.innerText = (popup._count + 1)+"/"+totalFeatures;
12321229

12331230
// creates > button, focuses next feature, if none exists focuses the current feature
1234-
let nextButton = L.DomUtil.create('a', "mapml-popup-button", div);
1235-
nextButton.href = '#';
1236-
nextButton.role = "button";
1231+
let nextButton = L.DomUtil.create("button", "mapml-popup-button", div);
1232+
nextButton.type = "button";
12371233
nextButton.title = "Next Feature";
12381234
nextButton.innerHTML = "<span aria-hidden='true'>&#10095;</span>";
12391235
L.DomEvent.disableClickPropagation(nextButton);
12401236
L.DomEvent.on(nextButton, 'click', L.DomEvent.stop);
12411237
L.DomEvent.on(nextButton, 'click', layer._nextFeature, popup);
12421238

12431239
// creates >| button, focuses map controls
1244-
let controlFocusButton = L.DomUtil.create('a',"mapml-popup-button", div);
1245-
controlFocusButton.href = '#';
1246-
controlFocusButton.role = "button";
1240+
let controlFocusButton = L.DomUtil.create("button", "mapml-popup-button", div);
1241+
controlFocusButton.type = "button";
12471242
controlFocusButton.title = "Focus Controls";
12481243
controlFocusButton.innerHTML = "<span aria-hidden='true'>&#10095;|</span>";
12491244
L.DomEvent.disableClickPropagation(controlFocusButton);

test/e2e/core/featureLinks.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jest.setTimeout(50000);
3636

3737
test("[" + browserType + "]" + " Sub-point inplace link adds new layer, parent feature has separate link", async () => {
3838
await page.hover(".leaflet-top.leaflet-right");
39-
await page.click("div > div.leaflet-control-container > div.leaflet-top.leaflet-right > div > section > div.leaflet-control-layers-overlays > fieldset:nth-child(2) > details > summary > div > a");
39+
await page.click("div > div.leaflet-control-container > div.leaflet-top.leaflet-right > div > section > div.leaflet-control-layers-overlays > fieldset:nth-child(2) > details > summary > div > button");
4040
await page.click("body > map");
4141
for(let i = 0; i < 6; i++)
4242
await page.keyboard.press("Tab");
@@ -68,7 +68,7 @@ jest.setTimeout(50000);
6868
describe("Main Part Link Tests in " + browserType, () => {
6969
test("[" + browserType + "]" + " Main part adds new layer", async () => {
7070
await page.hover(".leaflet-top.leaflet-right");
71-
await page.click("div > div.leaflet-control-container > div.leaflet-top.leaflet-right > div > section > div.leaflet-control-layers-overlays > fieldset:nth-child(2) > details > summary > div > a");
71+
await page.click("div > div.leaflet-control-container > div.leaflet-top.leaflet-right > div > section > div.leaflet-control-layers-overlays > fieldset:nth-child(2) > details > summary > div > button");
7272
await page.click("body > map");
7373
for(let i = 0; i < 5; i++)
7474
await page.keyboard.press("Tab");

test/e2e/core/keyboardInteraction.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ jest.setTimeout(50000);
125125

126126
describe("Feature Popup Tab Navigation Tests in " + browserType, () => {
127127
test("[" + browserType + "]" + " Inline features popup focus order", async () => {
128-
await page.click("div > div.leaflet-control-container > div.leaflet-top.leaflet-left > div.mapml-reload-button.leaflet-bar.leaflet-control > a");
128+
await page.click("div > div.leaflet-control-container > div.leaflet-top.leaflet-left > div.mapml-reload-button.leaflet-bar.leaflet-control > button");
129129
await page.evaluateHandle(() => document.getElementById("vector").removeAttribute("checked"));
130130
await page.evaluateHandle(() => document.getElementById("query").removeAttribute("checked"));
131131
await page.click("body");
@@ -246,7 +246,7 @@ jest.setTimeout(50000);
246246
expect(f).toEqual("M285 373L460 380L468 477L329 459z");
247247
});
248248

249-
test("[" + browserType + "]" + " Focus Controls focuses the first <a> child in control div", async () => {
249+
test("[" + browserType + "]" + " Focus Controls focuses the first <button> child in control div", async () => {
250250
await page.click("body > mapml-viewer");
251251
await page.keyboard.press("Shift+F10");
252252
await page.keyboard.press("t");

test/e2e/core/mapContextMenu.test.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ jest.setTimeout(50000);
8787
);
8888
await page.waitForTimeout(1000);
8989
await page.click("body > map", { button: "right" });
90-
await page.click("div > div.mapml-contextmenu > a:nth-child(1)");
90+
await page.click("div > div.mapml-contextmenu > button:nth-child(1)");
9191
await page.waitForTimeout(1000);
9292
const extent = await page.$eval(
9393
"body > map",
@@ -103,7 +103,7 @@ jest.setTimeout(50000);
103103
});
104104
test("[" + browserType + "]" + " Context menu, back item at intial location", async () => {
105105
await page.click("body > map", { button: "right" });
106-
await page.click("div > div.mapml-contextmenu > a:nth-child(1)");
106+
await page.click("div > div.mapml-contextmenu > button:nth-child(1)");
107107
await page.waitForTimeout(1000);
108108
const extent = await page.$eval(
109109
"body > map",
@@ -119,7 +119,7 @@ jest.setTimeout(50000);
119119
});
120120
test("[" + browserType + "]" + " Context menu, forward item", async () => {
121121
await page.click("body > map", { button: "right" });
122-
await page.click("div > div.mapml-contextmenu > a:nth-child(2)");
122+
await page.click("div > div.mapml-contextmenu > button:nth-child(2)");
123123
await page.waitForTimeout(1000);
124124
const extent = await page.$eval(
125125
"body > map",
@@ -134,7 +134,7 @@ jest.setTimeout(50000);
134134
});
135135
test("[" + browserType + "]" + " Context menu, forward item at most recent location", async () => {
136136
await page.click("body > map", { button: "right" });
137-
await page.click("div > div.mapml-contextmenu > a:nth-child(2)");
137+
await page.click("div > div.mapml-contextmenu > button:nth-child(2)");
138138
await page.waitForTimeout(1000);
139139
const extent = await page.$eval(
140140
"body > map",
@@ -156,7 +156,7 @@ jest.setTimeout(50000);
156156
);
157157

158158
await page.click("body > map", { button: "right" });
159-
await page.click("div > div.mapml-contextmenu > a:nth-child(5)");
159+
await page.click("div > div.mapml-contextmenu > button:nth-child(5)");
160160

161161
const controlsOff = await page.$eval(
162162
"div > div.leaflet-control-container > div.leaflet-top.leaflet-left",
@@ -174,7 +174,7 @@ jest.setTimeout(50000);
174174
);
175175

176176
await page.click("body > map", { button: "right" });
177-
await page.click("div > div.mapml-contextmenu > a:nth-child(5)");
177+
await page.click("div > div.mapml-contextmenu > button:nth-child(5)");
178178

179179
const controlsOff = await page.$eval(
180180
"div > div.leaflet-control-container > div.leaflet-top.leaflet-left",
@@ -203,9 +203,9 @@ jest.setTimeout(50000);
203203
expect(valueBefore).toEqual("0.5");
204204

205205
await page.click("body > map", { button: "right" });
206-
await page.click("div > div.mapml-contextmenu > a:nth-child(5)");
206+
await page.click("div > div.mapml-contextmenu > button:nth-child(5)");
207207
await page.click("body > map", { button: "right" });
208-
await page.click("div > div.mapml-contextmenu > a:nth-child(5)");
208+
await page.click("div > div.mapml-contextmenu > button:nth-child(5)");
209209

210210
const valueAfter = await page.$eval(
211211
"div > div.leaflet-control-container > div.leaflet-top.leaflet-right > div > section > div.leaflet-control-layers-overlays > fieldset > details > details > input",
@@ -224,7 +224,7 @@ jest.setTimeout(50000);
224224
await page.keyboard.press("Tab");
225225

226226
await page.keyboard.press("Enter");
227-
await page.click("#mapml-copy-submenu > a:nth-child(10)");
227+
await page.click("#mapml-copy-submenu > button:nth-child(10)");
228228

229229
await page.click("body > textarea");
230230
await page.keyboard.press("Control+v");

test/e2e/core/mapElement.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ jest.setTimeout(50000);
7070
});
7171

7272
test("[" + browserType + "]" + " Reload button takes you back to initial state", async () => {
73-
await page.click("div > div.leaflet-control-container > div.leaflet-top.leaflet-left > div.mapml-reload-button.leaflet-bar.leaflet-control > a");
73+
await page.click("div > div.leaflet-control-container > div.leaflet-top.leaflet-left > div.mapml-reload-button.leaflet-bar.leaflet-control > button");
7474
await page.waitForTimeout(1000);
7575
const extent = await page.$eval(
7676
"body > map",

test/e2e/layers/queryLink.test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ jest.setTimeout(50000);
7676
});
7777
describe("Queried Feature Tests in " + browserType, () => {
7878
test("[" + browserType + "]" + " First feature added + popup content updated ", async () => {
79-
await page.click("div > div.leaflet-control-container > div.leaflet-top.leaflet-left > div.mapml-reload-button.leaflet-bar.leaflet-control > a");
79+
await page.click("div > div.leaflet-control-container > div.leaflet-top.leaflet-left > div.mapml-reload-button.leaflet-bar.leaflet-control > button");
8080
await page.click("div");
8181
await page.waitForSelector("div > div.leaflet-pane.leaflet-map-pane > div.leaflet-pane.leaflet-popup-pane > div");
8282
const feature = await page.$eval(
@@ -93,7 +93,7 @@ jest.setTimeout(50000);
9393
});
9494

9595
test("[" + browserType + "]" + " Next feature added + popup content updated ", async () => {
96-
await page.click("div > div.leaflet-pane.leaflet-map-pane > div.leaflet-pane.leaflet-popup-pane > div > div.leaflet-popup-content-wrapper > div > div > nav > a:nth-child(4)");
96+
await page.click("div > div.leaflet-pane.leaflet-map-pane > div.leaflet-pane.leaflet-popup-pane > div > div.leaflet-popup-content-wrapper > div > div > nav > button:nth-child(4)");
9797
const feature = await page.$eval(
9898
"div > div.leaflet-pane.leaflet-map-pane > div.leaflet-pane.leaflet-overlay-pane > div:nth-child(1) > div:nth-child(5) > svg > g > g > path",
9999
(tile) => tile.getAttribute("d")
@@ -108,7 +108,7 @@ jest.setTimeout(50000);
108108
});
109109

110110
test("[" + browserType + "]" + " Previous feature added + popup content updated ", async () => {
111-
await page.click("div > div.leaflet-pane.leaflet-map-pane > div.leaflet-pane.leaflet-popup-pane > div > div.leaflet-popup-content-wrapper > div > div > nav > a:nth-child(2)");
111+
await page.click("div > div.leaflet-pane.leaflet-map-pane > div.leaflet-pane.leaflet-popup-pane > div > div.leaflet-popup-content-wrapper > div > div > nav > button:nth-child(2)");
112112
const feature = await page.$eval(
113113
"div > div.leaflet-pane.leaflet-map-pane > div.leaflet-pane.leaflet-overlay-pane > div:nth-child(1) > div:nth-child(5) > svg > g > g > path",
114114
(tile) => tile.getAttribute("d")
@@ -124,7 +124,7 @@ jest.setTimeout(50000);
124124

125125
test("[" + browserType + "]" + " PCRS feature added + popup content updated ", async () => {
126126
for (let i = 0; i < 2; i++)
127-
await page.click("div > div.leaflet-pane.leaflet-map-pane > div.leaflet-pane.leaflet-popup-pane > div > div.leaflet-popup-content-wrapper > div > div > nav > a:nth-child(4)");
127+
await page.click("div > div.leaflet-pane.leaflet-map-pane > div.leaflet-pane.leaflet-popup-pane > div > div.leaflet-popup-content-wrapper > div > div > nav > button:nth-child(4)");
128128
const feature = await page.$eval(
129129
"div > div.leaflet-pane.leaflet-map-pane > div.leaflet-pane.leaflet-overlay-pane > div:nth-child(1) > div:nth-child(5) > svg > g > g > path",
130130
(tile) => tile.getAttribute("d")
@@ -139,7 +139,7 @@ jest.setTimeout(50000);
139139
});
140140

141141
test("[" + browserType + "]" + " TCRS feature added + popup content updated ", async () => {
142-
await page.click("div > div.leaflet-pane.leaflet-map-pane > div.leaflet-pane.leaflet-popup-pane > div > div.leaflet-popup-content-wrapper > div > div > nav > a:nth-child(4)");
142+
await page.click("div > div.leaflet-pane.leaflet-map-pane > div.leaflet-pane.leaflet-popup-pane > div > div.leaflet-popup-content-wrapper > div > div > nav > button:nth-child(4)");
143143
const feature = await page.$eval(
144144
"div > div.leaflet-pane.leaflet-map-pane > div.leaflet-pane.leaflet-overlay-pane > div:nth-child(1) > div:nth-child(5) > svg > g > g > path",
145145
(tile) => tile.getAttribute("d")
@@ -154,7 +154,7 @@ jest.setTimeout(50000);
154154
});
155155

156156
test("[" + browserType + "]" + " Tilematrix feature added + popup content updated ", async () => {
157-
await page.click("div > div.leaflet-pane.leaflet-map-pane > div.leaflet-pane.leaflet-popup-pane > div > div.leaflet-popup-content-wrapper > div > div > nav > a:nth-child(4)");
157+
await page.click("div > div.leaflet-pane.leaflet-map-pane > div.leaflet-pane.leaflet-popup-pane > div > div.leaflet-popup-content-wrapper > div > div > nav > button:nth-child(4)");
158158
const feature = await page.$eval(
159159
"div > div.leaflet-pane.leaflet-map-pane > div.leaflet-pane.leaflet-overlay-pane > div:nth-child(1) > div:nth-child(5) > svg > g > g > path",
160160
(tile) => tile.getAttribute("d")
@@ -168,7 +168,7 @@ jest.setTimeout(50000);
168168
expect(popup).toEqual("TILEMATRIX Test");
169169
});
170170
test("[" + browserType + "]" + " Synthesized point, valid location ", async () => {
171-
await page.click("div > div.leaflet-pane.leaflet-map-pane > div.leaflet-pane.leaflet-popup-pane > div > div.leaflet-popup-content-wrapper > div > div > nav > a:nth-child(4)");
171+
await page.click("div > div.leaflet-pane.leaflet-map-pane > div.leaflet-pane.leaflet-popup-pane > div > div.leaflet-popup-content-wrapper > div > div > nav > button:nth-child(4)");
172172
const feature = await page.$eval(
173173
"div > div.leaflet-pane.leaflet-map-pane > div.leaflet-pane.leaflet-overlay-pane > div:nth-child(1) > div:nth-child(5) > svg > g > g > path",
174174
(tile) => tile.getAttribute("d")

0 commit comments

Comments
 (0)