close on escape
This commit is contained in:
parent
9842ebeb12
commit
1ab74d67ca
@ -1,14 +1,25 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { vOnClickOutside } from "@vueuse/components";
|
import { vOnClickOutside } from "@vueuse/components";
|
||||||
import { defineEmits, defineProps } from "vue";
|
import { defineEmits, defineProps, onMounted, onUnmounted } from "vue";
|
||||||
|
|
||||||
const emit = defineEmits(["close-modal"]);
|
const emit = defineEmits(["close-modal"]);
|
||||||
const props = defineProps({ title: String });
|
const props = defineProps({ title: String });
|
||||||
|
|
||||||
// todo close on escape
|
|
||||||
function close() {
|
function close() {
|
||||||
emit("close-modal");
|
emit("close-modal");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function keyUpHandler(e) {
|
||||||
|
if (e.key == "Escape") close();
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
window.addEventListener("keyup", keyUpHandler);
|
||||||
|
});
|
||||||
|
|
||||||
|
onUnmounted(() => {
|
||||||
|
window.removeEventListener("keyup", keyUpHandler);
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
Loading…
Reference in New Issue
Block a user