#1275 for TieredMenu
parent
1bdf46a22c
commit
05565212bc
|
@ -28,6 +28,12 @@ const TieredMenuProps = [
|
||||||
type: "boolean",
|
type: "boolean",
|
||||||
default: "true",
|
default: "true",
|
||||||
description: "Whether to automatically manage layering."
|
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."
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ interface TieredMenuProps {
|
||||||
appendTo?: string;
|
appendTo?: string;
|
||||||
autoZIndex?: boolean;
|
autoZIndex?: boolean;
|
||||||
baseZIndex?: number;
|
baseZIndex?: number;
|
||||||
|
exact?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
declare class TieredMenu {
|
declare class TieredMenu {
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
<Teleport :to="appendTo" :disabled="!popup">
|
<Teleport :to="appendTo" :disabled="!popup">
|
||||||
<transition name="p-connected-overlay" @enter="onEnter" @leave="onLeave" @after-leave="onAfterLeave">
|
<transition name="p-connected-overlay" @enter="onEnter" @leave="onLeave" @after-leave="onAfterLeave">
|
||||||
<div :ref="containerRef" :class="containerClass" v-if="popup ? visible : true" v-bind="$attrs" @click="onOverlayClick">
|
<div :ref="containerRef" :class="containerClass" v-if="popup ? visible : true" v-bind="$attrs" @click="onOverlayClick">
|
||||||
<TieredMenuSub :model="model" :root="true" :popup="popup" @leaf-click="onLeafClick" :template="$slots.item" />
|
<TieredMenuSub :model="model" :root="true" :popup="popup" @leaf-click="onLeafClick" :template="$slots.item" :exact="exact" />
|
||||||
</div>
|
</div>
|
||||||
</transition>
|
</transition>
|
||||||
</Teleport>
|
</Teleport>
|
||||||
|
@ -36,6 +36,10 @@ export default {
|
||||||
baseZIndex: {
|
baseZIndex: {
|
||||||
type: Number,
|
type: Number,
|
||||||
default: 0
|
default: 0
|
||||||
|
},
|
||||||
|
exact: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
target: null,
|
target: null,
|
||||||
|
|
|
@ -4,13 +4,13 @@
|
||||||
<li :class="getItemClass(item)" :style="item.style" v-if="visible(item) && !item.separator"
|
<li :class="getItemClass(item)" :style="item.style" v-if="visible(item) && !item.separator"
|
||||||
@mouseenter="onItemMouseEnter($event, item)" role="none">
|
@mouseenter="onItemMouseEnter($event, item)" role="none">
|
||||||
<template v-if="!template">
|
<template v-if="!template">
|
||||||
<router-link v-if="item.to && !disabled(item)" :to="item.to" custom v-slot="{navigate, href}">
|
<router-link v-if="item.to && !disabled(item)" :to="item.to" custom v-slot="{navigate, href, isActive, isExactActive}">
|
||||||
<a :href="href" @click="onItemClick($event, item, navigate)" :class="getLinkClass(item)" v-ripple @keydown="onItemKeyDown($event, item)" role="menuitem">
|
<a :href="href" @click="onItemClick($event, item, navigate)" :class="linkClass(item, {isActive, isExactActive})" v-ripple @keydown="onItemKeyDown($event, item)" role="menuitem">
|
||||||
<span :class="['p-menuitem-icon', item.icon]"></span>
|
<span :class="['p-menuitem-icon', item.icon]"></span>
|
||||||
<span class="p-menuitem-text">{{item.label}}</span>
|
<span class="p-menuitem-text">{{item.label}}</span>
|
||||||
</a>
|
</a>
|
||||||
</router-link>
|
</router-link>
|
||||||
<a v-else :href="item.url" :class="getLinkClass(item)" :target="item.target" :aria-haspopup="item.items != null" :aria-expanded="item === activeItem"
|
<a v-else :href="item.url" :class="linkClass(item)" :target="item.target" :aria-haspopup="item.items != null" :aria-expanded="item === activeItem"
|
||||||
@click="onItemClick($event, item)" @keydown="onItemKeyDown($event, item)" role="menuitem" :tabindex="disabled(item) ? null : '0'" v-ripple>
|
@click="onItemClick($event, item)" @keydown="onItemKeyDown($event, item)" role="menuitem" :tabindex="disabled(item) ? null : '0'" v-ripple>
|
||||||
<span :class="['p-menuitem-icon', item.icon]"></span>
|
<span :class="['p-menuitem-icon', item.icon]"></span>
|
||||||
<span class="p-menuitem-text">{{item.label}}</span>
|
<span class="p-menuitem-text">{{item.label}}</span>
|
||||||
|
@ -19,7 +19,7 @@
|
||||||
</template>
|
</template>
|
||||||
<component v-else :is="template" :item="item"></component>
|
<component v-else :is="template" :item="item"></component>
|
||||||
<TieredMenuSub :model="item.items" v-if="visible(item) && item.items" :key="item.label + '_sub_'" :template="template"
|
<TieredMenuSub :model="item.items" v-if="visible(item) && item.items" :key="item.label + '_sub_'" :template="template"
|
||||||
@leaf-click="onLeafClick" @keydown-item="onChildItemKeyDown" :parentActive="item === activeItem" />
|
@leaf-click="onLeafClick" @keydown-item="onChildItemKeyDown" :parentActive="item === activeItem" :exact="exact" />
|
||||||
</li>
|
</li>
|
||||||
<li :class="['p-menu-separator', item.class]" :style="item.style" v-if="visible(item) && item.separator" :key="'separator' + i.toString()" role="separator"></li>
|
<li :class="['p-menu-separator', item.class]" :style="item.style" v-if="visible(item) && item.separator" :key="'separator' + i.toString()" role="separator"></li>
|
||||||
</template>
|
</template>
|
||||||
|
@ -53,6 +53,10 @@ export default {
|
||||||
template: {
|
template: {
|
||||||
type: Object,
|
type: Object,
|
||||||
default: null
|
default: null
|
||||||
|
},
|
||||||
|
exact: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
documentClickListener: null,
|
documentClickListener: null,
|
||||||
|
@ -200,8 +204,12 @@ export default {
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
getLinkClass(item) {
|
linkClass(item, routerProps) {
|
||||||
return ['p-menuitem-link', {'p-disabled': this.disabled(item)}];
|
return ['p-menuitem-link', {
|
||||||
|
'p-disabled': this.disabled(item),
|
||||||
|
'router-link-active': routerProps && routerProps.isActive,
|
||||||
|
'router-link-active-exact': this.exact && routerProps && routerProps.isExactActive
|
||||||
|
}];
|
||||||
},
|
},
|
||||||
bindDocumentClickListener() {
|
bindDocumentClickListener() {
|
||||||
if (!this.documentClickListener) {
|
if (!this.documentClickListener) {
|
||||||
|
|
|
@ -182,6 +182,18 @@ toggle(event) {
|
||||||
</template>
|
</template>
|
||||||
</TieredMenu>
|
</TieredMenu>
|
||||||
</template>
|
</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>
|
||||||
|
<TieredMenu :model="items">
|
||||||
|
<template #item="{item}">
|
||||||
|
<router-link :to="item.to" custom v-slot="{href, route, navigate, isActive, isExactActive}">
|
||||||
|
<a :href="href" @click="navigate" :class="{'active-link': isActive, 'active-link-exact": isExactActive}>{{route.fullPath}}</a>
|
||||||
|
</router-link>
|
||||||
|
</template>
|
||||||
|
</TieredMenu>
|
||||||
|
</template>
|
||||||
</code></pre>
|
</code></pre>
|
||||||
|
|
||||||
<h5>Properties</h5>
|
<h5>Properties</h5>
|
||||||
|
@ -226,6 +238,12 @@ toggle(event) {
|
||||||
<td>boolean</td>
|
<td>boolean</td>
|
||||||
<td>true</td>
|
<td>true</td>
|
||||||
<td>Whether to automatically manage layering.</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>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
Loading…
Reference in New Issue