Skip to content

Commit

Permalink
全モーダルに対応
Browse files Browse the repository at this point in the history
  • Loading branch information
mehm8128 committed Nov 8, 2023
1 parent 0ba03c0 commit e4038bb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
15 changes: 1 addition & 14 deletions 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, onMounted, onUnmounted, reactive } from 'vue'
import { computed, reactive } from 'vue'
import useFileMeta from '/@/composables/files/useFileMeta'
import { useModalStore } from '/@/store/ui/modal'
Expand All @@ -34,19 +34,6 @@ 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
8 changes: 8 additions & 0 deletions src/store/ui/modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ const useModalStorePinia = defineStore('ui/modal', () => {
}
}

const onKeyDown = (e: KeyboardEvent) => {
if (e.key === 'Escape' && shouldShowModal.value) {
popModal()
}
}

window.addEventListener('keydown', onKeyDown)

return {
isOnInitialModalRoute,
isClearingModal,
Expand Down

0 comments on commit e4038bb

Please sign in to comment.