Skip to content

Commit 3b5eacd

Browse files
Anshpreet8Anshpreet
andauthored
Focus on Layer Menu Item or Link if Remove Button is clicked (#600)
* focus on layer menu item/link if remove button clicked * fixed getting the shadow root * removed unused function * made some fixes * added timeouts to featureLinks test Co-authored-by: Anshpreet <[email protected]>
1 parent 73e770d commit 3b5eacd

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/mapml/layers/MapLayer.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,21 @@ export var MapMLLayer = L.Layer.extend({
425425
//L.DomEvent.disableClickPropagation(removeControlButton);
426426
L.DomEvent.on(removeControlButton, 'click', L.DomEvent.stop);
427427
L.DomEvent.on(removeControlButton, 'click', (e)=>{
428+
let fieldset = 0, elem, root;
429+
root = mapEl.tagName === "MAPML-VIEWER" ? mapEl.shadowRoot : mapEl.querySelector(".mapml-web-map").shadowRoot;
430+
if(e.target.closest("fieldset").nextElementSibling && !e.target.closest("fieldset").nextElementSibling.disbaled){
431+
elem = e.target.closest("fieldset").previousElementSibling;
432+
while(elem){
433+
fieldset += 2; // find the next layer menu item
434+
elem = elem.previousElementSibling;
435+
}
436+
} else {
437+
// focus on the link
438+
elem = "link";
439+
}
428440
mapEl.removeChild(e.target.closest("fieldset").querySelector("span").layer._layerEl);
441+
elem = elem ? root.querySelector(".leaflet-control-attribution").firstElementChild: elem = root.querySelectorAll('input')[fieldset];
442+
setTimeout(() => elem.focus(), 800); // a timeout is set so "pressed remove layer" is announced first
429443
}, this);
430444

431445
let itemSettingControlButton = L.DomUtil.create('button', 'mapml-layer-item-settings-control', layerItemControls);

test/e2e/core/featureLinks.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ describe("Playwright Feature Links Tests", () => {
2525
test("Sub-point inplace link adds new layer, parent feature has separate link", async () => {
2626
await page.hover(".leaflet-top.leaflet-right");
2727
await page.click("div > div.leaflet-control-container > div.leaflet-top.leaflet-right > div > section > div.leaflet-control-layers-overlays > fieldset:nth-child(2) > div:nth-child(1) > div > button:nth-child(1)");
28+
await page.waitForTimeout(850);
2829
await page.click("body > map");
2930
for(let i = 0; i < 6; i++) {
3031
await page.keyboard.press("Tab");
@@ -59,6 +60,7 @@ describe("Playwright Feature Links Tests", () => {
5960
test("Main part adds new layer", async () => {
6061
await page.hover(".leaflet-top.leaflet-right");
6162
await page.click("div > div.leaflet-control-container > div.leaflet-top.leaflet-right > div > section > div.leaflet-control-layers-overlays > fieldset:nth-child(2) > div:nth-child(1) > div > button:nth-child(1)");
63+
await page.waitForTimeout(850);
6264
await page.click("body > map");
6365
for(let i = 0; i < 5; i++) {
6466
await page.keyboard.press("Tab");

0 commit comments

Comments
 (0)