diff --git a/frontend/components/Base/Modal.vue b/frontend/components/Base/Modal.vue index 0aee636..c1e7591 100644 --- a/frontend/components/Base/Modal.vue +++ b/frontend/components/Base/Modal.vue @@ -32,6 +32,12 @@ }, }); + function escClose(e: KeyboardEvent) { + if (e.key === "Escape") { + close(); + } + } + function close() { if (props.readonly) { emit("cancel"); @@ -42,4 +48,12 @@ const modalId = useId(); const modal = useVModel(props, "modelValue", emit); + + watchEffect(() => { + if (modal.value) { + document.addEventListener("keydown", escClose); + } else { + document.removeEventListener("keydown", escClose); + } + }); diff --git a/frontend/components/Item/CreateModal.vue b/frontend/components/Item/CreateModal.vue index 1b9bec5..5c1bdee 100644 --- a/frontend/components/Item/CreateModal.vue +++ b/frontend/components/Item/CreateModal.vue @@ -1,20 +1,14 @@