Dismiss popups with escape (#1426)

Co-authored-by: Anbraten <anton@ju60.de>
This commit is contained in:
Lukas 2022-11-18 11:42:04 +01:00 committed by GitHub
parent 482678daf5
commit 1786c0554a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -14,11 +14,23 @@
</template>
<script lang="ts" setup>
defineProps<{
import { onKeyStroke } from '@vueuse/core';
import { toRef } from 'vue';
const props = defineProps<{
open: boolean;
}>();
defineEmits<{
const emit = defineEmits<{
(event: 'close'): void;
}>();
const open = toRef(props, 'open');
onKeyStroke('Escape', (e) => {
e.preventDefault();
if (open.value) {
emit('close');
}
});
</script>