Skip to content

Commit

Permalink
fix(theme): leaking event listener when going back/forward on Safari …
Browse files Browse the repository at this point in the history
…on iOS (#3658) (#3671)

Co-authored-by: Divyansh Singh <40380293+brc-dd@users.noreply.github.com>
  • Loading branch information
0xlau and brc-dd committed Apr 26, 2024
1 parent e60c101 commit 1a72181
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/client/theme-default/components/VPLocalNavOutlineDropdown.vue
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { onClickOutside, onKeyStroke } from '@vueuse/core'
import { onKeyStroke } from '@vueuse/core'
import { onContentUpdated } from 'vitepress'
import { nextTick, ref } from 'vue'
import { nextTick, ref, watch } from 'vue'
import { useData } from '../composables/data'
import { resolveTitle, type MenuItem } from '../composables/outline'
import VPDocOutlineItem from './VPDocOutlineItem.vue'
Expand All @@ -17,8 +17,18 @@ const vh = ref(0)
const main = ref<HTMLDivElement>()
const items = ref<HTMLDivElement>()
onClickOutside(main, () => {
open.value = false
function closeOnClickOutside(e: Event) {
if (!main.value?.contains(e.target as Node)) {
open.value = false
}
}
watch(open, (value) => {
if (value) {
document.addEventListener('click', closeOnClickOutside)
return
}
document.removeEventListener('click', closeOnClickOutside)
})
onKeyStroke('Escape', () => {
Expand Down

0 comments on commit 1a72181

Please sign in to comment.