Skip to content

Commit 27c2904

Browse files
committed
Enhance keyboard navigation: implement number-key zoom shortcuts and prevent conflicts with Leaflet's zoom handler
1 parent 67c0d8d commit 27c2904

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

pcd-website/src/components/MapView.vue

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,18 @@ function handleKeydown(e: KeyboardEvent) {
145145
const mapEl = document.getElementById('map');
146146
if (mapEl && (mapEl === document.activeElement || mapEl.contains(document.activeElement))) {
147147
e.preventDefault();
148-
document.getElementById('burger-btn')?.focus();
148+
mapEl.focus();
149+
}
150+
}
151+
} else if (!isTextInput && /^[0-9]$/.test(e.key)) {
152+
const mapEl = document.getElementById('map');
153+
if (mapEl && (mapEl.contains(document.activeElement) || document.activeElement === mapEl)) {
154+
e.preventDefault();
155+
e.stopPropagation();
156+
if (e.key === '0') {
157+
mapInstance?.setView([20, 10], 3);
158+
} else {
159+
mapInstance?.setZoom(parseInt(e.key));
149160
}
150161
}
151162
} else if (e.key === 'M' || e.key === 'm') {
@@ -175,6 +186,13 @@ onMounted(async () => {
175186
mapInstance = map;
176187
leafletRef = L;
177188
189+
// Remove digit keyCodes (48–57) from Leaflet's built-in zoom handler so our
190+
// number-key zoom shortcuts don't conflict (e.g. keyCode 54 = '6' is zoom-out).
191+
const kb = (map as any).keyboard;
192+
if (kb?._zoomKeys) {
193+
for (let code = 48; code <= 57; code++) delete kb._zoomKeys[code];
194+
}
195+
178196
L.control.zoom({ position: 'bottomleft' }).addTo(map);
179197
180198
// Manage tab order for Leaflet-injected elements:

0 commit comments

Comments
 (0)