Skip to content

Commit 1a72181

Browse files
0xlaubrc-dd
andauthoredApr 26, 2024··
fix(theme): leaking event listener when going back/forward on Safari on iOS (#3658) (#3671)
Co-authored-by: Divyansh Singh <40380293+brc-dd@users.noreply.github.com>
1 parent e60c101 commit 1a72181

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed
 

‎src/client/theme-default/components/VPLocalNavOutlineDropdown.vue

+14-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script setup lang="ts">
2-
import { onClickOutside, onKeyStroke } from '@vueuse/core'
2+
import { onKeyStroke } from '@vueuse/core'
33
import { onContentUpdated } from 'vitepress'
4-
import { nextTick, ref } from 'vue'
4+
import { nextTick, ref, watch } from 'vue'
55
import { useData } from '../composables/data'
66
import { resolveTitle, type MenuItem } from '../composables/outline'
77
import VPDocOutlineItem from './VPDocOutlineItem.vue'
@@ -17,8 +17,18 @@ const vh = ref(0)
1717
const main = ref<HTMLDivElement>()
1818
const items = ref<HTMLDivElement>()
1919
20-
onClickOutside(main, () => {
21-
open.value = false
20+
function closeOnClickOutside(e: Event) {
21+
if (!main.value?.contains(e.target as Node)) {
22+
open.value = false
23+
}
24+
}
25+
26+
watch(open, (value) => {
27+
if (value) {
28+
document.addEventListener('click', closeOnClickOutside)
29+
return
30+
}
31+
document.removeEventListener('click', closeOnClickOutside)
2232
})
2333
2434
onKeyStroke('Escape', () => {

0 commit comments

Comments
 (0)
Please sign in to comment.