2
0
mirror of https://github.com/frappe/books.git synced 2024-12-23 11:29:03 +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> </div>
</template> </template>
<script> <script lang="ts">
export default { import { defineComponent } from 'vue';
export default defineComponent({
props: { props: {
openModal: { openModal: {
default: false, default: false,
type: Boolean, type: Boolean,
}, },
setCloseListener: {
default: true,
type: Boolean,
},
}, },
emits: ['closemodal'], 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> </script>

View File

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