File tree 1 file changed +14
-4
lines changed
src/client/theme-default/components
1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change 1
1
<script setup lang="ts">
2
- import { onClickOutside , onKeyStroke } from ' @vueuse/core'
2
+ import { onKeyStroke } from ' @vueuse/core'
3
3
import { onContentUpdated } from ' vitepress'
4
- import { nextTick , ref } from ' vue'
4
+ import { nextTick , ref , watch } from ' vue'
5
5
import { useData } from ' ../composables/data'
6
6
import { resolveTitle , type MenuItem } from ' ../composables/outline'
7
7
import VPDocOutlineItem from ' ./VPDocOutlineItem.vue'
@@ -17,8 +17,18 @@ const vh = ref(0)
17
17
const main = ref <HTMLDivElement >()
18
18
const items = ref <HTMLDivElement >()
19
19
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 )
22
32
})
23
33
24
34
onKeyStroke (' Escape' , () => {
You can’t perform that action at this time.
0 commit comments