2
0
mirror of https://github.com/frappe/books.git synced 2024-12-23 03:19:01 +00:00

fix(ux): add Escape listener on Modal

This commit is contained in:
18alantom 2022-10-17 22:38:06 +05:30
parent 90c8516e62
commit 795df3e8b9
2 changed files with 28 additions and 4 deletions

View File

@ -25,14 +25,38 @@
</div>
</template>
<script>
export default {
<script lang="ts">
import { defineComponent } from 'vue';
export default defineComponent({
props: {
openModal: {
default: false,
type: Boolean,
},
setCloseListener: {
default: true,
type: Boolean,
},
},
emits: ['closemodal'],
};
watch: {
openModal(value: boolean) {
if (value) {
document.addEventListener('keyup', this.escapeEventListener);
} else {
document.removeEventListener('keyup', this.escapeEventListener);
}
},
},
methods: {
escapeEventListener(event: KeyboardEvent) {
if (event.code !== 'Escape') {
return;
}
this.$emit('closemodal');
},
},
});
</script>

View File

@ -11,7 +11,7 @@
</div>
<!-- Search Modal -->
<Modal :open-modal="openModal" @closemodal="close">
<Modal :open-modal="openModal" @closemodal="close" :set-close-listener="false">
<!-- Search Input -->
<div class="p-1">
<input