Skip to content

Commit 62efa61

Browse files
committed
fix(createNested): add clear() method for proper state reset
- Add clear() that resets children, parents, openedIds, and group state - Preserve open state across nav rebuilds in useNavNested - Fix duplicate divider when combining skill and feature filters
1 parent 580839f commit 62efa61

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

apps/docs/src/components/app/AppNav.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@
6060
if (hasPage(configuredNav.value, path)) return null
6161
return findPage(app.nav, path)
6262
})
63+
64+
// Check if nav has real content (not just dividers)
65+
const hasNavContent = computed(() =>
66+
configuredNav.value.some(item => !('divider' in item)),
67+
)
6368
const navRef = useTemplateRef<AtomExpose>('nav')
6469
6570
// Match Tailwind's md breakpoint (768px) for nav visibility
@@ -180,7 +185,8 @@
180185
</template>
181186

182187
<template v-if="selectedLevels.size > 0">
183-
<li class="px-4">
188+
<!-- Skip divider if Active page section already added one and nav has no real content -->
189+
<li v-if="!filteredOutPage || hasNavContent" class="px-4">
184190
<AppDivider />
185191
</li>
186192

apps/docs/src/composables/useNavNested.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,15 @@ export function createNavNested (nav: MaybeRefOrGetter<NavItem[]>) {
8989
const scrollEnabled = shallowRef(false)
9090

9191
// SSR-safe: Build tree structure on server and client
92+
// Preserve open state across nav changes (e.g., filtering)
9293
watch(() => toValue(nav), items => {
94+
const savedOpenIds = [...nested.openedIds]
9395
nested.clear()
9496
nested.onboard(navToNestedItems(items))
97+
// Restore any open IDs that still exist in the new tree
98+
if (savedOpenIds.length > 0) {
99+
nested.open(savedOpenIds.filter(id => nested.has(id)))
100+
}
95101
}, { immediate: true })
96102

97103
// Top-level sections to open on first visit

packages/0/src/composables/createNested/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,13 +588,17 @@ export function createNested<
588588
return registrations.map(registration => register(registration))
589589
}
590590

591-
function reset (): void {
591+
function clear (): void {
592592
children.clear()
593593
parents.clear()
594594
openedIds.clear()
595595
group.reset()
596596
}
597597

598+
function reset (): void {
599+
clear()
600+
}
601+
598602
const context = {
599603
...group,
600604
children: children as ReadonlyMap<ID, readonly ID[]>,
@@ -630,6 +634,7 @@ export function createNested<
630634
unregister,
631635
offboard,
632636
onboard,
637+
clear,
633638
reset,
634639
get size () {
635640
return group.size

packages/0/src/composables/createNested/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ export interface NestedContext<Z extends NestedTicket> extends Omit<GroupContext
164164
unregister: (id: ID, cascade?: boolean) => void
165165
/** Offboard multiple nodes, optionally cascading */
166166
offboard: (ids: ID[], cascade?: boolean) => void
167+
/** Clear all nodes and nested state (children, parents, openedIds) */
168+
clear: () => void
167169
}
168170

169171
/**

0 commit comments

Comments
 (0)