Skip to content

Commit

Permalink
ファイルモーダル開いてるときにescキーを押したら閉じられるように
Browse files Browse the repository at this point in the history
  • Loading branch information
mehm8128 committed Nov 1, 2023
1 parent 0ef6320 commit 0ba03c0
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/components/Modal/FileModal/FileModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import FileModalImage from '/@/components/Modal/FileModal/FileModalImage.vue'
import FileModalFile from '/@/components/Modal/FileModal/FileModalFile.vue'
import FileModalVideo from '/@/components/Modal/FileModal/FileModalVideo.vue'
import FileModalAudio from '/@/components/Modal/FileModal/FileModalAudio.vue'
import { computed, reactive } from 'vue'
import { computed, onMounted, onUnmounted, reactive } from 'vue'
import useFileMeta from '/@/composables/files/useFileMeta'
import { useModalStore } from '/@/store/ui/modal'
Expand All @@ -34,6 +34,19 @@ const fileIdState = reactive({
})
const { fileMeta, fileType } = useFileMeta(fileIdState)
const { clearModal } = useModalStore()
const onKeyDown = (e: KeyboardEvent) => {
if (e.key === 'Escape') {
clearModal()
}
}
onMounted(() => {
window.addEventListener('keydown', onKeyDown)
})
onUnmounted(() => {
window.removeEventListener('keydown', onKeyDown)
})
</script>

<style module lang="scss">
Expand Down

0 comments on commit 0ba03c0

Please sign in to comment.