File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed
src/client/theme-default/components Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change 1
1
<script lang="ts" setup>
2
- import { ref , watchPostEffect , nextTick } from ' vue'
2
+ import { ref , watchPostEffect } from ' vue'
3
+ import { disableBodyScroll , clearAllBodyScrollLocks } from ' body-scroll-lock'
3
4
import { useSidebar } from ' ../composables/sidebar.js'
4
5
import VPSidebarGroup from ' ./VPSidebarGroup.vue'
5
6
@@ -10,12 +11,22 @@ const props = defineProps<{
10
11
}>()
11
12
12
13
// a11y: focus Nav element when menu has opened
13
- let navEl = ref <(Element & { focus(): void }) | null >(null )
14
+ let navEl = ref <HTMLElement | null >(null )
15
+
16
+ function lockBodyScroll() {
17
+ disableBodyScroll (navEl .value ! , { reserveScrollBarGap: true })
18
+ }
19
+
20
+ function unlockBodyScroll() {
21
+ clearAllBodyScrollLocks ()
22
+ }
14
23
15
24
watchPostEffect (async () => {
16
25
if (props .open ) {
17
- await nextTick ()
26
+ lockBodyScroll ()
18
27
navEl .value ?.focus ()
28
+ } else {
29
+ unlockBodyScroll ()
19
30
}
20
31
})
21
32
</script >
You can’t perform that action at this time.
0 commit comments