From a7ba49c2c251cd15712c249b05b2b2f459c312c0 Mon Sep 17 00:00:00 2001 From: James Lyne Date: Wed, 26 May 2021 23:55:50 +0100 Subject: [PATCH] Focus map on Esc --- src/components/Map.vue | 12 ++++++++++++ src/components/map/MapContextMenu.vue | 1 - 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/components/Map.vue b/src/components/Map.vue index e68c769..77c6a0c 100644 --- a/src/components/Map.vue +++ b/src/components/Map.vue @@ -205,6 +205,8 @@ export default defineComponent({ // markerZoomAnimation: false, })) as DynmapMap; + window.addEventListener('keydown', this.handleKeydown); + this.leaflet.createPane('vectors'); this.leaflet.addControl(new LoadingControl({ @@ -221,7 +223,17 @@ export default defineComponent({ }); }, + unmounted() { + window.removeEventListener('keydown', this.handleKeydown); + }, + methods: { + handleKeydown(e: KeyboardEvent) { + if(e.key === 'Escape') { + e.preventDefault(); + this.leaflet.getContainer().focus(); + } + }, updateFollow(player: DynmapPlayer, newFollow: boolean) { const store = useStore(), followMapName = store.state.configuration.followMap, diff --git a/src/components/map/MapContextMenu.vue b/src/components/map/MapContextMenu.vue index 572d373..b67d270 100644 --- a/src/components/map/MapContextMenu.vue +++ b/src/components/map/MapContextMenu.vue @@ -114,7 +114,6 @@ export default defineComponent({ const handleEsc = (e: KeyboardEvent) => { if (e.key === "Escape" && menuVisible.value) { closeContextMenu(); - props.leaflet.getContainer().focus(); } }, closeContextMenu = () => {