Skip to content

Commit

Permalink
Enable closing panel sections with the escape key (just like modals)
Browse files Browse the repository at this point in the history
  • Loading branch information
Iapetus-11 committed Nov 28, 2024
1 parent cd5830d commit 2a468da
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/views/game/panels/PanelSection.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { ref, watch } from 'vue';
import { onBeforeMount, onUnmounted, ref, watch } from 'vue';
import { faChevronRight } from '@fortawesome/pro-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import { useTailwindBreakpoint } from '@/utils';
Expand Down Expand Up @@ -28,6 +28,20 @@
}
},
);
function onWindowKeyPress(ev: KeyboardEvent) {
if (ev.key === 'Escape') {
mobileTrayOpen.value = false;
}
}
onBeforeMount(() => {
window.addEventListener('keydown', onWindowKeyPress);
});
onUnmounted(() => {
window.removeEventListener('keydown', onWindowKeyPress);
});
</script>

<template>
Expand Down

0 comments on commit 2a468da

Please sign in to comment.