2022-09-06 12:03:37 +00:00
|
|
|
<template>
|
|
|
|
<ul class="p-submenu-list" role="tree">
|
|
|
|
<template v-for="(item, i) of model" :key="label(item) + i.toString()">
|
2022-09-14 11:26:01 +00:00
|
|
|
<li v-if="visible(item) && !item.separator" role="none" :class="getItemClass(item)" :style="item.style">
|
2022-09-06 12:03:37 +00:00
|
|
|
<template v-if="!template">
|
2022-09-14 11:26:01 +00:00
|
|
|
<router-link v-if="item.to && !disabled(item)" v-slot="{ navigate, href, isActive: isRouterActive, isExactActive }" :to="item.to" custom>
|
|
|
|
<a :href="href" :class="linkClass(item, { isActive: isRouterActive, isExactActive })" @click="onItemClick($event, item, navigate)" role="treeitem" :aria-expanded="isActive(item)">
|
2022-09-06 12:03:37 +00:00
|
|
|
<span :class="['p-menuitem-icon', item.icon]"></span>
|
2022-09-14 11:26:01 +00:00
|
|
|
<span class="p-menuitem-text">{{ label(item) }}</span>
|
2022-09-06 12:03:37 +00:00
|
|
|
</a>
|
|
|
|
</router-link>
|
2022-09-14 11:26:01 +00:00
|
|
|
<a
|
|
|
|
v-else
|
|
|
|
:href="item.url"
|
|
|
|
:class="linkClass(item)"
|
|
|
|
:target="item.target"
|
|
|
|
@click="onItemClick($event, item)"
|
|
|
|
@keydown="onItemKeydown($event, item)"
|
|
|
|
role="treeitem"
|
|
|
|
:aria-expanded="isActive(item)"
|
|
|
|
:tabindex="disabled(item) ? null : '0'"
|
|
|
|
>
|
|
|
|
<span v-if="item.items" :class="getSubmenuIcon(item)"></span>
|
2022-09-06 12:03:37 +00:00
|
|
|
<span :class="['p-menuitem-icon', item.icon]"></span>
|
2022-09-14 11:26:01 +00:00
|
|
|
<span class="p-menuitem-text">{{ label(item) }}</span>
|
2022-09-06 12:03:37 +00:00
|
|
|
</a>
|
|
|
|
</template>
|
|
|
|
<component v-else :is="template" :item="item"></component>
|
|
|
|
<transition name="p-toggleable-content">
|
2022-09-14 11:26:01 +00:00
|
|
|
<div v-show="isActive(item)" class="p-toggleable-content">
|
|
|
|
<PanelMenuSub v-if="visible(item) && item.items" :key="label(item) + '_sub_'" :model="item.items" :template="template" :expandedKeys="expandedKeys" @item-toggle="$emit('item-toggle', $event)" :exact="exact" />
|
2022-09-06 12:03:37 +00:00
|
|
|
</div>
|
|
|
|
</transition>
|
|
|
|
</li>
|
2022-09-14 11:26:01 +00:00
|
|
|
<li v-if="visible(item) && item.separator" :key="'separator' + i.toString()" :class="['p-menu-separator', item.class]" :style="item.style"></li>
|
2022-09-06 12:03:37 +00:00
|
|
|
</template>
|
|
|
|
</ul>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
name: 'PanelMenuSub',
|
|
|
|
emits: ['item-toggle'],
|
|
|
|
props: {
|
2022-09-14 11:26:01 +00:00
|
|
|
model: {
|
2022-09-06 12:03:37 +00:00
|
|
|
type: null,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
template: {
|
|
|
|
type: Function,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
expandedKeys: {
|
|
|
|
type: null,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
exact: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
activeItem: null
|
2022-09-14 11:26:01 +00:00
|
|
|
};
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
onItemClick(event, item, navigate) {
|
|
|
|
if (this.isActive(item) && this.activeItem === null) {
|
|
|
|
this.activeItem = item;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.disabled(item)) {
|
|
|
|
event.preventDefault();
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item.command) {
|
|
|
|
item.command({
|
|
|
|
originalEvent: event,
|
|
|
|
item: item
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
if (this.activeItem && this.activeItem === item) this.activeItem = null;
|
|
|
|
else this.activeItem = item;
|
2022-09-06 12:03:37 +00:00
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
this.$emit('item-toggle', { item: item, expanded: this.activeItem != null });
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
if (item.to && navigate) {
|
|
|
|
navigate(event);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onItemKeydown(event, item) {
|
|
|
|
if (event.which === 13) {
|
|
|
|
this.onItemClick(event, item);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
getItemClass(item) {
|
|
|
|
return ['p-menuitem', item.className];
|
|
|
|
},
|
|
|
|
linkClass(item, routerProps) {
|
2022-09-14 11:26:01 +00:00
|
|
|
return [
|
|
|
|
'p-menuitem-link',
|
|
|
|
{
|
|
|
|
'p-disabled': this.disabled(item),
|
|
|
|
'router-link-active': routerProps && routerProps.isActive,
|
|
|
|
'router-link-active-exact': this.exact && routerProps && routerProps.isExactActive
|
|
|
|
}
|
|
|
|
];
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
isActive(item) {
|
|
|
|
return this.expandedKeys ? this.expandedKeys[item.key] : item === this.activeItem;
|
|
|
|
},
|
|
|
|
getSubmenuIcon(item) {
|
|
|
|
const active = this.isActive(item);
|
2022-09-14 11:26:01 +00:00
|
|
|
|
|
|
|
return ['p-panelmenu-icon pi pi-fw', { 'pi-angle-right': !active, 'pi-angle-down': active }];
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
visible(item) {
|
2022-09-14 11:26:01 +00:00
|
|
|
return typeof item.visible === 'function' ? item.visible() : item.visible !== false;
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
disabled(item) {
|
2022-09-14 11:26:01 +00:00
|
|
|
return typeof item.disabled === 'function' ? item.disabled() : item.disabled;
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
label(item) {
|
2022-09-14 11:26:01 +00:00
|
|
|
return typeof item.label === 'function' ? item.label() : item.label;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
};
|
2022-09-06 12:03:37 +00:00
|
|
|
</script>
|