@@ -315,20 +315,20 @@ Just set the `pinned` prop.
315315 class =" app-navigation-entry-wrapper" >
316316 <component
317317 :is =" isRouterLink ? 'router-link' : 'NcVNodes'"
318- v-slot =" { href: routerLinkHref, navigate, isActive }"
318+ v-slot =" { href: routerLinkHref, navigate, isExactActive }"
319319 v-bind =" { ...isRouterLink && { custom: true, to } }" >
320320 <div
321321 class =" app-navigation-entry"
322322 :class =" {
323323 'app-navigation-entry--editing': editingActive,
324324 'app-navigation-entry--deleted': undo,
325- active: (to && isActive) || active ,
325+ active: isActiveLink(isExactActive) ,
326326 }" >
327327 <!-- Icon and name -->
328328 <a
329329 v-if =" !undo"
330330 class =" app-navigation-entry-link"
331- :aria-current =" active || (to && isActive ) ? 'page' : undefined"
331+ :aria-current =" isActiveLink(isExactActive ) ? 'page' : undefined"
332332 :aria-description =" ariaDescription"
333333 :aria-expanded =" !!$slots.default ? opened.toString() : undefined"
334334 :href =" href || routerLinkHref || '#'"
@@ -346,7 +346,7 @@ Just set the `pinned` prop.
346346 :class =" { [icon]: icon }" >
347347 <NcLoadingIcon v-if =" loading" />
348348 <!-- @slot Slot for the optional leading icon. This slots get the `active`-slot attribute passed which is based on the vue-routers active route or the `active` prop. -->
349- <slot v-else name =" icon" :active =" active || (to && isActive )" />
349+ <slot v-else name =" icon" :active =" isActiveLink(isExactActive )" />
350350 </div >
351351 <span class =" app-navigation-entry__name" :class =" { 'hidden-visually': editingActive }" >
352352 {{ name }}
@@ -356,7 +356,7 @@ Just set the `pinned` prop.
356356 ref =" editingInput"
357357 v-model =" editingValue"
358358 :placeholder =" editPlaceholder !== '' ? editPlaceholder : name"
359- :primary =" (to && isActive) || active "
359+ :primary =" isActiveLink(isExactActive) "
360360 @cancel =" cancelEditing"
361361 @confirm =" handleEditingDone" />
362362 </div >
@@ -391,7 +391,7 @@ Just set the `pinned` prop.
391391 :open =" menuOpen"
392392 :force-menu =" forceMenu"
393393 :default-icon =" menuIcon"
394- :variant =" (to && isActive) || active ? 'tertiary-on-primary' : 'tertiary'"
394+ :variant =" isActiveLink(isExactActive) ? 'tertiary-on-primary' : 'tertiary'"
395395 @update:open =" onMenuToggle" >
396396 <template #icon >
397397 <!-- @slot Slot for the custom menu icon -->
@@ -420,7 +420,7 @@ Just set the `pinned` prop.
420420 </div >
421421 <NcAppNavigationIconCollapsible
422422 v-if =" allowCollapse && !!$slots.default"
423- :active =" (to && isActive) || active "
423+ :active =" isActiveLink(isExactActive) "
424424 :open =" opened"
425425 @click.prevent.stop =" toggleCollapse" />
426426
@@ -465,12 +465,13 @@ export default {
465465
466466 props: {
467467 /**
468- * If you are not using vue-router you can use the property to set this item as the active navigation entry.
468+ * If you are not using vue-router or if you want to overwrite the vue-router active state,
469+ * you can use the property to set the active state of the navigation entry.
469470 * When using vue-router and the `to` property this is set automatically.
470471 */
471472 active: {
472473 type: Boolean ,
473- default: false ,
474+ default: undefined ,
474475 },
475476
476477 /**
@@ -814,6 +815,21 @@ export default {
814815 // Match any protocol
815816 return href && href .match (/ [a-z ] + :\/\/ / i )
816817 },
818+
819+ /**
820+ * Determines whether the navigation item should be marked as active.
821+ *
822+ * When the `active` prop is set, it is used instead of the router active state
823+ *
824+ * @param {boolean} isExactActive - The router-provided active state for exact matches
825+ * @return {boolean} True if the navigation item should be rendered in active state
826+ */
827+ isActiveLink (isExactActive ) {
828+ if (this .active !== undefined ) {
829+ return this .active
830+ }
831+ return isExactActive
832+ },
817833 },
818834}
819835< / script>
0 commit comments