Skip to content

Commit

Permalink
fix: revert back to old collapse logic (#539)
Browse files Browse the repository at this point in the history
* ⏪ (collapse) revert back to old collapse logic

* 🐛 (navigation) preserve uncollapsing for first visited category
  • Loading branch information
Tahul authored Jul 8, 2021
1 parent 9b67c34 commit f1915e4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
34 changes: 26 additions & 8 deletions src/defaultTheme/components/molecules/AsideNavigation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
:key="link.to"
:title="link.title"
:docs="link.children"
:collapse="link.collapse === true"
:collapse="link.collapse"
@toggle="toggleLinks(link)"
/>
<AsideNavigationItem v-else :key="link.to" :docs="[link]" />
Expand All @@ -83,8 +83,10 @@ export default defineComponent({
setup() {
const { $docus } = useContext()
// Replicate currentNav locally
const links = ref($docus.currentNav.value.links)
// Watch updates on currentNav
watch(
$docus.currentNav,
newVal => {
Expand All @@ -93,22 +95,38 @@ export default defineComponent({
{ deep: true }
)
function toggleLinks(link) {
const newLinks = $docus.currentNav.value.links.map(l => {
l = { ...l }
// Uncollapse current category on first navigation
watch(
links,
newVal => {
newVal.forEach(link => {
if (link.children && link.children.length > 0) {
const isCategoryActive = link.children.some(document => $docus.isLinkActive(document.to))
if (isCategoryActive) {
link.collapse = false
}
}
})
},
{ immediate: true }
)
if (link.slug === l.slug) {
l.collapse = !link.collapse
// Toggle a link
const toggleLinks = link => {
links.value = links.value.map(l => {
if (l.slug === link.slug) {
l.collapse = !l.collapse
}
return l
})
links.value = newLinks
}
// Get parent
const parent = computed(() => $docus.currentNav.value.parent)
// Get last release value
const lastRelease = computed(() => $docus.lastRelease?.value)
return { toggleLinks, links, parent, lastRelease }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
</template>

<script>
import { computed, defineComponent, ref, useContext } from '@nuxtjs/composition-api'
import { computed, watch, defineComponent, ref, useContext } from '@nuxtjs/composition-api'
export default defineComponent({
props: {
Expand Down

0 comments on commit f1915e4

Please sign in to comment.