mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-30 03:01:54 +00:00
feat: auto-select and scroll to matching nav category on search
This commit is contained in:
@@ -34,6 +34,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<nav
|
<nav
|
||||||
|
ref="navRef"
|
||||||
class="scrollbar-hide flex flex-1 flex-col gap-1 overflow-y-auto px-3 py-4"
|
class="scrollbar-hide flex flex-1 flex-col gap-1 overflow-y-auto px-3 py-4"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
@@ -45,10 +46,11 @@
|
|||||||
<NavItem
|
<NavItem
|
||||||
v-for="item in group.items"
|
v-for="item in group.items"
|
||||||
:key="item.id"
|
:key="item.id"
|
||||||
|
:data-nav-id="item.id"
|
||||||
:icon="item.icon"
|
:icon="item.icon"
|
||||||
:badge="item.badge"
|
:badge="item.badge"
|
||||||
:active="activeCategoryKey === item.id"
|
:active="activeCategoryKey === item.id"
|
||||||
@click="activeCategoryKey = item.id"
|
@click="onNavItemClick(item.id)"
|
||||||
>
|
>
|
||||||
{{ item.label }}
|
{{ item.label }}
|
||||||
</NavItem>
|
</NavItem>
|
||||||
@@ -85,7 +87,7 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import Tag from 'primevue/tag'
|
import Tag from 'primevue/tag'
|
||||||
import { computed, provide, ref, watch } from 'vue'
|
import { computed, nextTick, provide, ref, watch } from 'vue'
|
||||||
|
|
||||||
import SearchBox from '@/components/common/SearchBox.vue'
|
import SearchBox from '@/components/common/SearchBox.vue'
|
||||||
import WorkspaceProfilePic from '@/components/common/WorkspaceProfilePic.vue'
|
import WorkspaceProfilePic from '@/components/common/WorkspaceProfilePic.vue'
|
||||||
@@ -131,14 +133,27 @@ const workspaceName = computed(() => workspaceStore.workspaceName)
|
|||||||
const {
|
const {
|
||||||
searchQuery,
|
searchQuery,
|
||||||
inSearch,
|
inSearch,
|
||||||
|
searchResultsCategories,
|
||||||
handleSearch: handleSearchBase,
|
handleSearch: handleSearchBase,
|
||||||
getSearchResults
|
getSearchResults
|
||||||
} = useSettingSearch()
|
} = useSettingSearch()
|
||||||
|
|
||||||
const authActions = useFirebaseAuthActions()
|
const authActions = useFirebaseAuthActions()
|
||||||
|
|
||||||
|
const navRef = ref<HTMLElement | null>(null)
|
||||||
const activeCategoryKey = ref<string | null>(defaultCategory.value?.key ?? null)
|
const activeCategoryKey = ref<string | null>(defaultCategory.value?.key ?? null)
|
||||||
|
|
||||||
|
watch(searchResultsCategories, (categories) => {
|
||||||
|
if (!inSearch.value || categories.size === 0) return
|
||||||
|
const firstMatch = navGroups.value
|
||||||
|
.flatMap((g) => g.items)
|
||||||
|
.find((item) => {
|
||||||
|
const node = findCategoryByKey(item.id)
|
||||||
|
return node && categories.has(node.label)
|
||||||
|
})
|
||||||
|
activeCategoryKey.value = firstMatch?.id ?? null
|
||||||
|
})
|
||||||
|
|
||||||
const activeSettingCategory = computed<SettingTreeNode | null>(() => {
|
const activeSettingCategory = computed<SettingTreeNode | null>(() => {
|
||||||
if (!activeCategoryKey.value) return null
|
if (!activeCategoryKey.value) return null
|
||||||
return (
|
return (
|
||||||
@@ -176,6 +191,14 @@ function handleSearch(query: string) {
|
|||||||
activeCategoryKey.value = query ? null : (defaultCategory.value?.key ?? null)
|
activeCategoryKey.value = query ? null : (defaultCategory.value?.key ?? null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onNavItemClick(id: string) {
|
||||||
|
if (inSearch.value) {
|
||||||
|
searchQuery.value = ''
|
||||||
|
handleSearchBase('')
|
||||||
|
}
|
||||||
|
activeCategoryKey.value = id
|
||||||
|
}
|
||||||
|
|
||||||
const searchResults = computed<ISettingGroup[]>(() => {
|
const searchResults = computed<ISettingGroup[]>(() => {
|
||||||
const category = activeCategoryKey.value
|
const category = activeCategoryKey.value
|
||||||
? findCategoryByKey(activeCategoryKey.value)
|
? findCategoryByKey(activeCategoryKey.value)
|
||||||
@@ -190,6 +213,13 @@ watch(activeCategoryKey, (newKey, oldKey) => {
|
|||||||
if (newKey === 'credits') {
|
if (newKey === 'credits') {
|
||||||
void authActions.fetchBalance()
|
void authActions.fetchBalance()
|
||||||
}
|
}
|
||||||
|
if (newKey) {
|
||||||
|
void nextTick(() => {
|
||||||
|
navRef.value
|
||||||
|
?.querySelector(`[data-nav-id="${newKey}"]`)
|
||||||
|
?.scrollIntoView({ block: 'nearest', behavior: 'smooth' })
|
||||||
|
})
|
||||||
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user