Skip to content

Commit f741b91

Browse files
authored
docs(app): improve navigation filtering logic (#5453)
1 parent dd81d46 commit f741b91

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

docs/app/layouts/docs.vue

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,25 @@ const { navigationByCategory } = useNavigation(navigation!)
1010
1111
const { contains } = useFilter({ sensitivity: 'base' })
1212
const filteredNavigation = computed(() => {
13-
if (!value.value) {
13+
if (!searchTerm.value) {
1414
return navigationByCategory.value
1515
}
1616
1717
return navigationByCategory.value.map(item => ({
1818
...item,
19-
children: item.children?.filter(child => contains(child.title as string, value.value) || contains(child.description as string, value.value))
19+
children: item.children?.filter(child => contains(child.title as string, searchTerm.value) || contains(child.description as string, searchTerm.value))
2020
})).filter(item => item.children && item.children.length > 0)
2121
})
2222
2323
const input = useTemplateRef('input')
24-
const value = ref('')
24+
const isActiveSearch = computed(() => route.path.startsWith('/docs/components'))
25+
const searchTerm = ref('')
26+
27+
watch(() => route.path, () => {
28+
if (!isActiveSearch.value) {
29+
searchTerm.value = ''
30+
}
31+
})
2532
2633
defineShortcuts({
2734
'/': {
@@ -39,8 +46,8 @@ defineShortcuts({
3946
<UPage>
4047
<template #left>
4148
<UPageAside>
42-
<template v-if="route.path.startsWith('/docs/components')" #top>
43-
<UInput ref="input" v-model="value" variant="soft" placeholder="Filter..." class="group">
49+
<template v-if="isActiveSearch" #top>
50+
<UInput ref="input" v-model="searchTerm" variant="soft" placeholder="Filter..." class="group">
4451
<template #trailing>
4552
<UKbd value="/" variant="subtle" class="ring-muted bg-transparent text-muted" />
4653
</template>

0 commit comments

Comments
 (0)