parent
de591af15b
commit
2f777041e5
|
@ -60,6 +60,10 @@ const MenuSlots = [
|
||||||
{
|
{
|
||||||
name: 'item',
|
name: 'item',
|
||||||
description: 'Template of a menuitem.'
|
description: 'Template of a menuitem.'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'itemicon',
|
||||||
|
description: 'Custom item icon template.'
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -80,6 +80,20 @@ export interface MenuSlots {
|
||||||
*/
|
*/
|
||||||
item: MenuItem;
|
item: MenuItem;
|
||||||
}): VNode[];
|
}): VNode[];
|
||||||
|
/**
|
||||||
|
* Custom item icon template.
|
||||||
|
* @param {Object} scope - item icon slot's params.
|
||||||
|
*/
|
||||||
|
itemicon(scope: {
|
||||||
|
/**
|
||||||
|
* Menuitem instance
|
||||||
|
*/
|
||||||
|
item: MenuItem;
|
||||||
|
/**
|
||||||
|
* Style class of the item icon element.
|
||||||
|
*/
|
||||||
|
class: any;
|
||||||
|
}): VNode[];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -24,12 +24,12 @@
|
||||||
<slot name="item" :item="item">{{ label(item) }}</slot>
|
<slot name="item" :item="item">{{ label(item) }}</slot>
|
||||||
</li>
|
</li>
|
||||||
<template v-for="(child, j) of item.items" :key="child.label + i + '_' + j">
|
<template v-for="(child, j) of item.items" :key="child.label + i + '_' + j">
|
||||||
<PVMenuitem v-if="visible(child) && !child.separator" :id="id + '_' + i + '_' + j" :item="child" :template="$slots.item" :exact="exact" :focusedOptionId="focusedOptionId" @item-click="itemClick" />
|
<PVMenuitem v-if="visible(child) && !child.separator" :id="id + '_' + i + '_' + j" :item="child" :templates="$slots" :exact="exact" :focusedOptionId="focusedOptionId" @item-click="itemClick" />
|
||||||
<li v-else-if="visible(child) && child.separator" :key="'separator' + i + j" :class="separatorClass(item)" :style="child.style" role="separator"></li>
|
<li v-else-if="visible(child) && child.separator" :key="'separator' + i + j" :class="separatorClass(item)" :style="child.style" role="separator"></li>
|
||||||
</template>
|
</template>
|
||||||
</template>
|
</template>
|
||||||
<li v-else-if="visible(item) && item.separator" :key="'separator' + i.toString()" :class="separatorClass(item)" :style="item.style" role="separator"></li>
|
<li v-else-if="visible(item) && item.separator" :key="'separator' + i.toString()" :class="separatorClass(item)" :style="item.style" role="separator"></li>
|
||||||
<PVMenuitem v-else :key="label(item) + i.toString()" :id="id + '_' + i" :item="item" :template="$slots.item" :exact="exact" :focusedOptionId="focusedOptionId" @item-click="itemClick" />
|
<PVMenuitem v-else :key="label(item) + i.toString()" :id="id + '_' + i" :item="item" :templates="$slots" :exact="exact" :focusedOptionId="focusedOptionId" @item-click="itemClick" />
|
||||||
</template>
|
</template>
|
||||||
</ul>
|
</ul>
|
||||||
<div v-if="$slots.end" class="p-menu-end">
|
<div v-if="$slots.end" class="p-menu-end">
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
<template>
|
<template>
|
||||||
<li v-if="visible()" :id="id" :class="containerClass()" role="menuitem" :style="item.style" :aria-label="label()" :aria-disabled="disabled()">
|
<li v-if="visible()" :id="id" :class="containerClass()" role="menuitem" :style="item.style" :aria-label="label()" :aria-disabled="disabled()">
|
||||||
<div class="p-menuitem-content" @click="onItemClick($event)">
|
<div class="p-menuitem-content" @click="onItemClick($event)">
|
||||||
<template v-if="!template">
|
<template v-if="!templates.item">
|
||||||
<router-link v-if="item.to && !disabled()" v-slot="{ navigate, href, isActive, isExactActive }" :to="item.to" custom>
|
<router-link v-if="item.to && !disabled()" v-slot="{ navigate, href, isActive, isExactActive }" :to="item.to" custom>
|
||||||
<a v-ripple :href="href" :class="linkClass({ isActive, isExactActive })" tabindex="-1" aria-hidden="true" @click="onItemActionClick($event, navigate)">
|
<a v-ripple :href="href" :class="linkClass({ isActive, isExactActive })" tabindex="-1" aria-hidden="true" @click="onItemActionClick($event, navigate)">
|
||||||
<span v-if="item.icon" :class="['p-menuitem-icon', item.icon]"></span>
|
<component :is="templates.itemicon || (item.icon ? 'span' : undefined)" :item="item" :class="iconClass" />
|
||||||
<span class="p-menuitem-text">{{ label() }}</span>
|
<span class="p-menuitem-text">{{ label() }}</span>
|
||||||
</a>
|
</a>
|
||||||
</router-link>
|
</router-link>
|
||||||
<a v-else v-ripple :href="item.url" :class="linkClass()" :target="item.target" tabindex="-1" aria-hidden="true">
|
<a v-else v-ripple :href="item.url" :class="linkClass()" :target="item.target" tabindex="-1" aria-hidden="true">
|
||||||
<span v-if="item.icon" :class="['p-menuitem-icon', item.icon]"></span>
|
<component :is="templates.itemicon || (item.icon ? 'span' : undefined)" :item="item" :class="iconClass" />
|
||||||
<span class="p-menuitem-text">{{ label() }}</span>
|
<span class="p-menuitem-text">{{ label() }}</span>
|
||||||
</a>
|
</a>
|
||||||
</template>
|
</template>
|
||||||
<component v-else :is="template" :item="item"></component>
|
<component v-else :is="templates.item" :item="item"></component>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
</template>
|
</template>
|
||||||
|
@ -28,7 +28,7 @@ export default {
|
||||||
emits: ['item-click'],
|
emits: ['item-click'],
|
||||||
props: {
|
props: {
|
||||||
item: null,
|
item: null,
|
||||||
template: null,
|
templates: null,
|
||||||
exact: null,
|
exact: null,
|
||||||
id: null,
|
id: null,
|
||||||
focusedOptionId: null
|
focusedOptionId: null
|
||||||
|
@ -68,6 +68,11 @@ export default {
|
||||||
return typeof this.item.label === 'function' ? this.item.label() : this.item.label;
|
return typeof this.item.label === 'function' ? this.item.label() : this.item.label;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
computed: {
|
||||||
|
iconClass() {
|
||||||
|
return ['p-menuitem-icon', this.item.icon];
|
||||||
|
}
|
||||||
|
},
|
||||||
directives: {
|
directives: {
|
||||||
ripple: Ripple
|
ripple: Ripple
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue