From 6e010cf2cbd2386a3cdff2f756ad0329df79f80c Mon Sep 17 00:00:00 2001 From: Wolfgang Date: Mon, 1 Dec 2025 18:56:12 +0100 Subject: [PATCH] feat(NcAppNavigationItem): use exact route matching and change active prop to be able to overwrite the vue-router state Signed-off-by: Wolfgang --- .../NcAppNavigationItem.vue | 34 ++++++++++++++----- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/src/components/NcAppNavigationItem/NcAppNavigationItem.vue b/src/components/NcAppNavigationItem/NcAppNavigationItem.vue index d3f46e6cb2..ecd11a23e7 100644 --- a/src/components/NcAppNavigationItem/NcAppNavigationItem.vue +++ b/src/components/NcAppNavigationItem/NcAppNavigationItem.vue @@ -315,7 +315,7 @@ Just set the `pinned` prop. class="app-navigation-entry-wrapper">
- +
{{ name }} @@ -357,7 +357,7 @@ Just set the `pinned` prop. ref="editingInput" v-model="editingValue" :placeholder="editPlaceholder !== '' ? editPlaceholder : name" - :primary="(to && isActive) || active" + :primary="isActiveLink(isExactActive)" @cancel="cancelEditing" @confirm="handleEditingDone" /> @@ -421,7 +421,7 @@ Just set the `pinned` prop. @@ -467,12 +467,13 @@ export default { props: { /** - * If you are not using vue-router you can use the property to set this item as the active navigation entry. + * If you are not using vue-router or if you want to overwrite the vue-router active state, + * you can use the property to set the active state of the navigation entry. * When using vue-router and the `to` property this is set automatically. */ active: { - type: Boolean, - default: false, + type: [Boolean, undefined], + default: undefined, }, /** @@ -817,6 +818,21 @@ export default { // Match any protocol return href && href.match(/[a-z]+:\/\//i) }, + + /** + * Determines whether the navigation item should be marked as active. + * + * When the `active` prop is set, it is used instead of the router active state + * + * @param {boolean} isExactActive - The router-provided active state for exact matches + * @return {boolean} True if the navigation item should be rendered in active state + */ + isActiveLink(isExactActive) { + if (this.active !== undefined) { + return this.active + } + return isExactActive + }, }, }