Skip to content

Commit 4cdfca4

Browse files
committed
refactor: auto-close mobile sidebar on click
1 parent 48b58e0 commit 4cdfca4

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

Diff for: src/components/layout/TheSidebarMobile.vue

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<script setup lang="ts">
22
const isOpen = ref(false)
33
const navigation = useNavigationStore()
4+
5+
// const route = useRoute()
6+
watch(useRoute(), () => (isOpen.value = false))
47
</script>
58

69
<template>
@@ -68,19 +71,16 @@ const navigation = useNavigationStore()
6871
<the-sidebar-navigation
6972
:navigation="navigation.mainNavigation"
7073
section-name="Introduction"
71-
@on-click="isOpen = false"
7274
/>
7375

7476
<the-sidebar-navigation
7577
:navigation="navigation.cheatsheetNavigation"
7678
section-name="Cheatsheet"
77-
@on-click="isOpen = false"
7879
/>
7980

8081
<the-sidebar-navigation
8182
:navigation="navigation.standardLibraryNavigation"
8283
section-name="Standard Library"
83-
@on-click="isOpen = false"
8484
/>
8585
</nav>
8686
</nav>

Diff for: src/components/layout/TheSidebarNavigation.vue

+10-10
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ interface Navigation {
55
[key: string]: any
66
}
77
8-
const emit = defineEmits(['on-click'])
8+
// const emit = defineEmits(['on-click'])
99
1010
defineProps<{
1111
sectionName: string
1212
navigation: Array<Navigation>
1313
}>()
1414
15-
const router = useRouter()
16-
const navigate = (item: Navigation) => {
17-
router.push(item.path)
18-
emit('on-click')
19-
}
15+
// const router = useRouter()
16+
// const navigate = (item: Navigation) => {
17+
// router.push(item.path)
18+
// emit('on-click')
19+
// }
2020
</script>
2121

2222
<template>
@@ -27,17 +27,17 @@ const navigate = (item: Navigation) => {
2727
class="mt-2 mb-6 space-y-2 border-l-2 border-slate-100 text-base dark:border-slate-800 lg:mt-4 lg:space-y-1.5 lg:border-slate-200 lg:text-sm"
2828
>
2929
<li v-for="item in navigation" :key="item.name" class="relative">
30-
<a
31-
class="-ml-px block cursor-pointer border-l border-transparent pl-4 transition duration-150"
30+
<router-link
31+
:to="item.path"
32+
class="-ml-px block border-l border-transparent pl-4 transition duration-150"
3233
:class="
3334
$route.path === item.path
3435
? 'border-current font-semibold text-sky-500 dark:text-sky-400'
3536
: 'text-slate-700 hover:border-slate-400 hover:text-slate-900 dark:text-slate-400 dark:hover:border-slate-500 dark:hover:text-slate-300'
3637
"
37-
@click="navigate(item)"
3838
>
3939
{{ item.name }}
40-
</a>
40+
</router-link>
4141
</li>
4242
</ul>
4343
</template>

0 commit comments

Comments
 (0)