Skip to content

Commit 12de277

Browse files
committed
Fix focusing on feature when number key is pressed
1 parent 8bc1317 commit 12de277

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/mapml/features/featureGroup.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ export var FeatureGroup = L.FeatureGroup.extend({
7979
this._map.featureIndex.inBoundFeatures[index].path.setAttribute("tabindex", 0);
8080
}
8181
}
82-
} else if (!([9, 16, 13, 27].includes(e.keyCode))){
82+
} else if (!([9, 16, 13, 27, 49, 50, 51, 52, 53, 54, 55].includes(e.keyCode))){
8383
this._map.featureIndex.currentIndex = 0;
8484
this._map.featureIndex.inBoundFeatures[0].path.focus();
8585
}
8686

8787
if(e.target.tagName.toUpperCase() !== "G") return;
88-
if((e.keyCode === 9 || e.keyCode === 16 || e.keyCode === 13) && e.type === "keyup") {
88+
if((e.keyCode === 9 || e.keyCode === 16 || e.keyCode === 13 || (e.keyCode >= 49 && e.keyCode <= 55)) && e.type === "keyup") {
8989
this.openTooltip();
9090
} else if (e.keyCode === 13 || e.keyCode === 32){
9191
this.closeTooltip();

src/mapml/layers/FeatureIndexOverlay.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export var FeatureIndexOverlay = L.Layer.extend({
1616
},
1717

1818
_checkOverlap: function () {
19+
this._map.fire("mapkeyboardfocused");
1920
let bounds = this._map.getPixelBounds();
2021
let center = bounds.getCenter();
2122
let wRatio = Math.abs(bounds.min.x - bounds.max.x) / (this._map.options.mapEl.width);
@@ -94,8 +95,12 @@ export var FeatureIndexOverlay = L.Layer.extend({
9495
let body = this._body;
9596
let key = e.originalEvent.keyCode;
9697
if (key >= 49 && key <= 55){
97-
let group = body.allFeatures[body.index][key - 49].group;
98-
if (group) group.focus();
98+
let feature = body.allFeatures[body.index][key - 49];
99+
let group = feature.group;
100+
if (group) {
101+
this._map.featureIndex.currentIndex = feature.index - 1;
102+
group.focus();
103+
}
99104
} else if(e.originalEvent.keyCode === 56){
100105
this._newContent(body, -1);
101106
} else if(e.originalEvent.keyCode === 57){

0 commit comments

Comments
 (0)