pull/1533/head
Cagatay Civici 2021-08-27 11:09:41 +03:00
parent 26eba9e055
commit 16fe00529e
5 changed files with 41 additions and 7 deletions

View File

@ -28,6 +28,12 @@ const MenuProps = [
type: "boolean",
default: "true",
description: "Whether to automatically manage layering."
},
{
name: "exact",
type: "boolean",
default: "true",
description: "Whether to apply 'router-link-active-exact' class if route exactly matches the item path."
}
];

View File

@ -6,6 +6,7 @@ interface MenuProps {
appendTo?: string;
autoZIndex?: boolean;
baseZIndex?: number;
exact?: boolean;
}
declare class Menu {

View File

@ -9,12 +9,12 @@
<slot name="item" :item="item">{{item.label}}</slot>
</li>
<template v-for="(child, j) of item.items" :key="child.label + i + j">
<Menuitem v-if="visible(child) && !child.separator" :item="child" @click="itemClick" :template="$slots.item" />
<Menuitem v-if="visible(child) && !child.separator" :item="child" @click="itemClick" :template="$slots.item" :exact="exact" />
<li v-else-if="visible(child) && child.separator" :class="['p-menu-separator', child.class]" :style="child.style" :key="'separator' + i + j" role="separator"></li>
</template>
</template>
<li v-else-if="visible(item) && item.separator" :class="['p-menu-separator', item.class]" :style="item.style" :key="'separator' + i.toString()" role="separator"></li>
<Menuitem v-else :key="item.label + i.toString()" :item="item" @click="itemClick" :template="$slots.item" />
<Menuitem v-else :key="item.label + i.toString()" :item="item" @click="itemClick" :template="$slots.item" :exact="exact" />
</template>
</ul>
</div>
@ -51,6 +51,10 @@ export default {
baseZIndex: {
type: Number,
default: 0
},
exact: {
type: Boolean,
default: true
}
},
data() {

View File

@ -1,8 +1,8 @@
<template>
<li :class="containerClass" role="none" :style="item.style" v-if="visible()">
<template v-if="!template">
<router-link v-if="item.to && !disabled(item)" :to="item.to" custom v-slot="{navigate, href}">
<a :href="href" @click="onClick($event, navigate)" :class="linkClass(item)" v-ripple role="menuitem">
<router-link v-if="item.to && !disabled(item)" :to="item.to" custom v-slot="{navigate, href, isActive, isExactActive}">
<a :href="href" @click="onClick($event, navigate)" :class="linkClass(item, {isActive, isExactActive})" v-ripple role="menuitem">
<span :class="['p-menuitem-icon', item.icon]"></span>
<span class="p-menuitem-text">{{item.label}}</span>
</a>
@ -25,7 +25,8 @@ export default {
emits: ['click'],
props: {
item: null,
template: null
template: null,
exact: null
},
methods: {
onClick(event, navigate) {
@ -35,8 +36,12 @@ export default {
navigate: navigate
});
},
linkClass(item) {
return ['p-menuitem-link', {'p-disabled': this.disabled(item)}];
linkClass(item, routerProps) {
return ['p-menuitem-link', {
'p-disabled': this.disabled(item),
'router-link-active': routerProps && routerProps.isActive,
'router-link-active-exact': this.exact && routerProps && routerProps.isExactActive
}];
},
visible() {
return (typeof this.item.visible === 'function' ? this.item.visible() : this.item.visible !== false);

View File

@ -95,6 +95,18 @@ toggle(event) {
&lt;/template&gt;
&lt;/Menu&gt;
</template>
</code></pre>
<p><i>router-link</i> with route configuration can also be used within templating for further customization.</p>
<pre v-code><code><template v-pre>
&lt;Menu :model="items"&gt;
&lt;template #item="{item}"&gt;
&lt;router-link :to="item.to" custom v-slot="{href, route, navigate, isActive, isExactActive}"&gt;
&lt;a :href="href" @click="navigate" :class="{'active-link': isActive, 'active-link-exact": isExactActive}&gt;{{route.fullPath}}&lt;/a&gt;
&lt;/router-link&gt;
&lt;/template&gt;
&lt;/Menu&gt;
</template>
</code></pre>
<h5>Properties</h5>
@ -139,6 +151,12 @@ toggle(event) {
<td>boolean</td>
<td>true</td>
<td>Whether to automatically manage layering.</td>
</tr>
<tr>
<td>exact</td>
<td>boolean</td>
<td>true</td>
<td>Whether to apply 'router-link-active-exact' class if route exactly matches the item path.</td>
</tr>
</tbody>
</table>