Skip to content

Commit 256275c

Browse files
authored
fix: a11y mobile menu items (#624)
1 parent d6e2e1a commit 256275c

File tree

3 files changed

+86
-6
lines changed

3 files changed

+86
-6
lines changed

app/components/MobileMenu.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
<script setup lang="ts">
2+
import { useFocusTrap } from '@vueuse/integrations/useFocusTrap'
3+
24
const isOpen = defineModel<boolean>('open', { default: false })
35
46
const { isConnected, npmUser, avatar: npmAvatar } = useConnector()
57
const { user: atprotoUser } = useAtproto()
68
9+
const navRef = useTemplateRef('navRef')
10+
const { activate, deactivate } = useFocusTrap(navRef, { allowOutsideClick: true })
11+
712
function closeMenu() {
813
isOpen.value = false
914
}
@@ -39,6 +44,8 @@ onKeyStroke(
3944
// Prevent body scroll when menu is open
4045
const isLocked = useScrollLock(document)
4146
watch(isOpen, open => (isLocked.value = open))
47+
watch(isOpen, open => (open ? nextTick(activate) : deactivate()))
48+
onUnmounted(deactivate)
4249
</script>
4350

4451
<template>
@@ -75,6 +82,7 @@ watch(isOpen, open => (isLocked.value = open))
7582
>
7683
<nav
7784
v-if="isOpen"
85+
ref="navRef"
7886
class="absolute inset-ie-0 top-0 bottom-0 w-72 bg-bg border-is border-border shadow-xl flex flex-col"
7987
>
8088
<!-- Header -->

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,10 @@
6666
"@vite-pwa/nuxt": "1.1.0",
6767
"@voidzero-dev/vite-plus-core": "0.0.0-833c515fa25cef20905a7f9affb156dfa6f151ab",
6868
"@vueuse/core": "14.2.0",
69+
"@vueuse/integrations": "14.2.0",
6970
"@vueuse/nuxt": "14.2.0",
7071
"@vueuse/router": "^14.2.0",
72+
"focus-trap": "^7.8.0",
7173
"marked": "17.0.1",
7274
"module-replacements": "2.11.0",
7375
"nuxt": "4.3.0",

pnpm-lock.yaml

Lines changed: 76 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)