Skip to content

Commit

Permalink
nav: fixing active section logic, fixing global nav breadcrumbs inter…
Browse files Browse the repository at this point in the history
…fering with JumpNav (#577)

* fixing checkActive function

* fixing instances when global nav interferes with JumpNav header store
  • Loading branch information
stephiescastle committed Aug 28, 2024
1 parent a33f69a commit 9c1bda3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
11 changes: 7 additions & 4 deletions packages/vue/src/components/NavDesktop/NavDesktop.vue
Original file line number Diff line number Diff line change
Expand Up @@ -246,14 +246,17 @@ export default defineComponent({
// to determine active class on menu links and 'more' menu links
checkActive(item: LinkObject) {
const urlKey = this.getUrlKey(item)
if (urlKey && this.breadcrumb && this.breadcrumb.menu_links) {
if (urlKey && this.breadcrumb?.menu_links) {
// key into the breadcrumbs for each section
const objArray = this.breadcrumb.menu_links[urlKey]
const sectionLinks = this.breadcrumb.menu_links[urlKey]
// check if any of the paths contained in the array are active
const isActive = objArray.some((el: BreadcrumbPathObject) => mixinIsActivePath(el.path))
const isActive = sectionLinks.some((link: BreadcrumbPathObject) =>
mixinIsActivePath(link.path)
)
if (isActive) {
mixinUpdateGlobalChildren(this.breadcrumb.menu_links[urlKey])
mixinUpdateGlobalChildren(sectionLinks)
}
console.log(isActive)
return isActive
}
return false
Expand Down
1 change: 1 addition & 0 deletions packages/vue/src/components/NavJumpMenu/NavJumpMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
ref="NavJumpMenuRef"
class="NavJumpMenu -hide-until-threshold"
:invert="invert"
jump-menu
>
<template v-for="(item, index) in theBreadcrumbs">
<template v-if="item.children && item.children.length > 0">
Expand Down
13 changes: 11 additions & 2 deletions packages/vue/src/components/NavSecondary/NavSecondary.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ export default defineComponent({
type: Boolean,
required: false,
default: false
},
jumpMenu: {
type: Boolean,
default: false
}
},
data(): {
Expand All @@ -101,9 +105,12 @@ export default defineComponent({
if (this.breadcrumb) {
// we also want to update the store to override secondary nav
mixinUpdateSecondary(JSON.parse(this.breadcrumb))
return JSON.parse(this.breadcrumb)
} else if (this.headerStore) {
return this.headerStore.globalChildren
if (!this.jumpMenu) {
return this.headerStore.globalChildren
}
}
return undefined
},
Expand All @@ -117,7 +124,9 @@ export default defineComponent({
mounted() {
if (this.enabled) {
// if there is a secondary nav displayed, then don't highlight the primary active item
mixinHighlightPrimary(false)
if (!this.jumpMenu) {
mixinHighlightPrimary(false)
}
}
if (
Expand Down
10 changes: 7 additions & 3 deletions packages/vue/src/utils/mixins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,16 @@ export const mixinHighlightPrimary = (value: boolean) => {
*/
export const mixinIsActivePath = (itemPath: string): Boolean => {
const route = useRoute()
const currentPath = route ? route.path : null
const path = itemPath
const ancestorPath = path ? (path.endsWith('/') ? path : path + '/') : null
const currentPath = route ? route.path : false
const path = itemPath.startsWith('http') ? itemPath.replace(/^.*\/\/[^/]+/, '') : itemPath
const ancestorPath = path ? (path.endsWith('/') ? path : path + '/') : false

if (currentPath && path && ancestorPath) {
if (currentPath === path) {
return true
} else if (currentPath.startsWith('/edu/events')) {
// special treatment since EDU combines News & Events in the main nav
return path.startsWith('/edu/news')
} else {
return currentPath.startsWith(ancestorPath)
}
Expand Down

0 comments on commit 9c1bda3

Please sign in to comment.