2022-09-06 12:03:37 +00:00
|
|
|
<template>
|
2023-11-09 14:18:51 +00:00
|
|
|
<transition name="p-tieredmenu" @enter="onEnter" v-bind="ptm('menu.transition')">
|
2024-04-30 13:03:20 +00:00
|
|
|
<ul v-if="level === 0 ? true : visible" :ref="containerRef" :class="level === 0 ? cx('rootList') : cx('submenu')" :tabindex="tabindex" v-bind="level === 0 ? ptm('rootList') : ptm('submenu')">
|
2023-11-09 14:18:51 +00:00
|
|
|
<template v-for="(processedItem, index) of items" :key="getItemKey(processedItem)">
|
|
|
|
<li
|
|
|
|
v-if="isItemVisible(processedItem) && !getItemProp(processedItem, 'separator')"
|
|
|
|
:id="getItemId(processedItem)"
|
|
|
|
:style="getItemProp(processedItem, 'style')"
|
2024-04-30 13:03:20 +00:00
|
|
|
:class="[cx('item', { processedItem }), getItemProp(processedItem, 'class')]"
|
2023-11-09 14:18:51 +00:00
|
|
|
role="menuitem"
|
|
|
|
:aria-label="getItemLabel(processedItem)"
|
|
|
|
:aria-disabled="isItemDisabled(processedItem) || undefined"
|
|
|
|
:aria-expanded="isItemGroup(processedItem) ? isItemActive(processedItem) : undefined"
|
|
|
|
:aria-haspopup="isItemGroup(processedItem) && !getItemProp(processedItem, 'to') ? 'menu' : undefined"
|
|
|
|
:aria-level="level + 1"
|
|
|
|
:aria-setsize="getAriaSetSize()"
|
|
|
|
:aria-posinset="getAriaPosInset(index)"
|
2024-04-30 13:03:20 +00:00
|
|
|
v-bind="getPTOptions(processedItem, index, 'item')"
|
2023-11-09 14:18:51 +00:00
|
|
|
:data-p-highlight="isItemActive(processedItem)"
|
|
|
|
:data-p-focused="isItemFocused(processedItem)"
|
|
|
|
:data-p-disabled="isItemDisabled(processedItem)"
|
|
|
|
>
|
2024-02-15 15:57:40 +00:00
|
|
|
<div
|
2024-04-30 13:03:20 +00:00
|
|
|
:class="cx('itemContent')"
|
2024-02-15 15:57:40 +00:00
|
|
|
@click="onItemClick($event, processedItem)"
|
|
|
|
@mouseenter="onItemMouseEnter($event, processedItem)"
|
|
|
|
@mousemove="onItemMouseMove($event, processedItem)"
|
2024-04-30 13:03:20 +00:00
|
|
|
v-bind="getPTOptions(processedItem, index, 'itemContent')"
|
2024-02-15 15:57:40 +00:00
|
|
|
>
|
2023-11-09 14:18:51 +00:00
|
|
|
<template v-if="!templates.item">
|
2024-04-30 13:03:20 +00:00
|
|
|
<a v-ripple :href="getItemProp(processedItem, 'url')" :class="cx('itemLink')" :target="getItemProp(processedItem, 'target')" tabindex="-1" aria-hidden="true" v-bind="getPTOptions(processedItem, index, 'itemLink')">
|
|
|
|
<component v-if="templates.itemicon" :is="templates.itemicon" :item="processedItem.item" :class="cx('itemIcon')" />
|
|
|
|
<span v-else-if="getItemProp(processedItem, 'icon')" :class="[cx('itemIcon'), getItemProp(processedItem, 'icon')]" v-bind="getPTOptions(processedItem, index, 'itemIcon')" />
|
|
|
|
<span :id="getItemLabelId(processedItem)" :class="cx('itemLabel')" v-bind="getPTOptions(processedItem, index, 'itemLabel')">{{ getItemLabel(processedItem) }}</span>
|
2023-11-09 14:18:51 +00:00
|
|
|
<template v-if="getItemProp(processedItem, 'items')">
|
|
|
|
<component v-if="templates.submenuicon" :is="templates.submenuicon" :class="cx('submenuIcon')" :active="isItemActive(processedItem)" v-bind="getPTOptions(processedItem, index, 'submenuIcon')" />
|
|
|
|
<AngleRightIcon v-else :class="cx('submenuIcon')" v-bind="getPTOptions(processedItem, index, 'submenuIcon')" />
|
|
|
|
</template>
|
|
|
|
</a>
|
|
|
|
</template>
|
|
|
|
<component v-else :is="templates.item" :item="processedItem.item" :hasSubmenu="getItemProp(processedItem, 'items')" :label="getItemLabel(processedItem)" :props="getMenuItemProps(processedItem, index)"></component>
|
|
|
|
</div>
|
|
|
|
<TieredMenuSub
|
|
|
|
v-if="isItemVisible(processedItem) && isItemGroup(processedItem)"
|
|
|
|
:id="getItemId(processedItem) + '_list'"
|
|
|
|
:style="sx('submenu', true, { processedItem })"
|
2023-12-29 08:34:58 +00:00
|
|
|
:aria-labelledby="getItemLabelId(processedItem)"
|
2023-11-09 14:18:51 +00:00
|
|
|
role="menu"
|
|
|
|
:menuId="menuId"
|
|
|
|
:focusedItemId="focusedItemId"
|
|
|
|
:items="processedItem.items"
|
|
|
|
:templates="templates"
|
|
|
|
:activeItemPath="activeItemPath"
|
|
|
|
:level="level + 1"
|
|
|
|
:visible="isItemActive(processedItem) && isItemGroup(processedItem)"
|
|
|
|
:pt="pt"
|
|
|
|
:unstyled="unstyled"
|
|
|
|
@item-click="$emit('item-click', $event)"
|
|
|
|
@item-mouseenter="$emit('item-mouseenter', $event)"
|
2024-02-15 15:57:40 +00:00
|
|
|
@item-mousemove="$emit('item-mousemove', $event)"
|
2023-11-09 14:18:51 +00:00
|
|
|
/>
|
|
|
|
</li>
|
|
|
|
<li
|
|
|
|
v-if="isItemVisible(processedItem) && getItemProp(processedItem, 'separator')"
|
|
|
|
:id="getItemId(processedItem)"
|
|
|
|
:style="getItemProp(processedItem, 'style')"
|
|
|
|
:class="[cx('separator'), getItemProp(processedItem, 'class')]"
|
|
|
|
role="separator"
|
|
|
|
v-bind="ptm('separator')"
|
|
|
|
></li>
|
|
|
|
</template>
|
|
|
|
</ul>
|
|
|
|
</transition>
|
2022-09-06 12:03:37 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2023-05-30 11:06:57 +00:00
|
|
|
import BaseComponent from 'primevue/basecomponent';
|
2023-04-18 12:53:43 +00:00
|
|
|
import AngleRightIcon from 'primevue/icons/angleright';
|
2022-09-06 12:03:37 +00:00
|
|
|
import Ripple from 'primevue/ripple';
|
2023-11-09 14:18:51 +00:00
|
|
|
import { DomHandler, ObjectUtils } from 'primevue/utils';
|
2023-08-30 13:28:00 +00:00
|
|
|
import { mergeProps } from 'vue';
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'TieredMenuSub',
|
2023-07-04 06:29:36 +00:00
|
|
|
hostName: 'TieredMenu',
|
2023-05-30 11:06:57 +00:00
|
|
|
extends: BaseComponent,
|
2024-02-15 15:57:40 +00:00
|
|
|
emits: ['item-click', 'item-mouseenter', 'item-mousemove'],
|
2023-11-09 14:18:51 +00:00
|
|
|
container: null,
|
2022-09-06 12:03:37 +00:00
|
|
|
props: {
|
2022-12-08 11:04:25 +00:00
|
|
|
menuId: {
|
|
|
|
type: String,
|
2022-09-06 12:03:37 +00:00
|
|
|
default: null
|
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
focusedItemId: {
|
|
|
|
type: String,
|
|
|
|
default: null
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
items: {
|
|
|
|
type: Array,
|
|
|
|
default: null
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
2023-11-09 14:18:51 +00:00
|
|
|
visible: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
level: {
|
|
|
|
type: Number,
|
|
|
|
default: 0
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
2023-04-17 06:38:00 +00:00
|
|
|
templates: {
|
2023-04-05 11:57:18 +00:00
|
|
|
type: Object,
|
2022-09-06 12:03:37 +00:00
|
|
|
default: null
|
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
activeItemPath: {
|
|
|
|
type: Object,
|
|
|
|
default: null
|
|
|
|
},
|
2023-05-29 12:31:43 +00:00
|
|
|
tabindex: {
|
|
|
|
type: Number,
|
|
|
|
default: 0
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2022-12-08 11:04:25 +00:00
|
|
|
getItemId(processedItem) {
|
|
|
|
return `${this.menuId}_${processedItem.key}`;
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
getItemKey(processedItem) {
|
|
|
|
return this.getItemId(processedItem);
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
2023-01-05 13:12:59 +00:00
|
|
|
getItemProp(processedItem, name, params) {
|
|
|
|
return processedItem && processedItem.item ? ObjectUtils.getItemValue(processedItem.item[name], params) : undefined;
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
getItemLabel(processedItem) {
|
|
|
|
return this.getItemProp(processedItem, 'label');
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
2023-12-29 08:34:58 +00:00
|
|
|
getItemLabelId(processedItem) {
|
|
|
|
return `${this.menuId}_${processedItem.key}_label`;
|
|
|
|
},
|
2023-07-25 09:12:10 +00:00
|
|
|
getPTOptions(processedItem, index, key) {
|
2023-04-27 14:16:09 +00:00
|
|
|
return this.ptm(key, {
|
2023-04-28 10:15:44 +00:00
|
|
|
context: {
|
2023-07-25 09:12:10 +00:00
|
|
|
item: processedItem,
|
|
|
|
index,
|
2023-04-27 14:16:09 +00:00
|
|
|
active: this.isItemActive(processedItem),
|
2023-10-17 10:06:59 +00:00
|
|
|
focused: this.isItemFocused(processedItem),
|
|
|
|
disabled: this.isItemDisabled(processedItem)
|
2023-04-27 14:16:09 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
isItemActive(processedItem) {
|
|
|
|
return this.activeItemPath.some((path) => path.key === processedItem.key);
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
isItemVisible(processedItem) {
|
|
|
|
return this.getItemProp(processedItem, 'visible') !== false;
|
|
|
|
},
|
|
|
|
isItemDisabled(processedItem) {
|
|
|
|
return this.getItemProp(processedItem, 'disabled');
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
isItemFocused(processedItem) {
|
|
|
|
return this.focusedItemId === this.getItemId(processedItem);
|
|
|
|
},
|
|
|
|
isItemGroup(processedItem) {
|
|
|
|
return ObjectUtils.isNotEmpty(processedItem.items);
|
|
|
|
},
|
2023-11-09 14:18:51 +00:00
|
|
|
onEnter() {
|
|
|
|
DomHandler.nestedPosition(this.container, this.level);
|
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
onItemClick(event, processedItem) {
|
2023-01-05 13:12:59 +00:00
|
|
|
this.getItemProp(processedItem, 'command', { originalEvent: event, item: processedItem.item });
|
2022-12-08 11:04:25 +00:00
|
|
|
this.$emit('item-click', { originalEvent: event, processedItem, isFocus: true });
|
|
|
|
},
|
|
|
|
onItemMouseEnter(event, processedItem) {
|
|
|
|
this.$emit('item-mouseenter', { originalEvent: event, processedItem });
|
|
|
|
},
|
2024-02-15 15:57:40 +00:00
|
|
|
onItemMouseMove(event, processedItem) {
|
|
|
|
this.$emit('item-mousemove', { originalEvent: event, processedItem });
|
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
getAriaSetSize() {
|
|
|
|
return this.items.filter((processedItem) => this.isItemVisible(processedItem) && !this.getItemProp(processedItem, 'separator')).length;
|
|
|
|
},
|
|
|
|
getAriaPosInset(index) {
|
|
|
|
return index - this.items.slice(0, index).filter((processedItem) => this.isItemVisible(processedItem) && this.getItemProp(processedItem, 'separator')).length + 1;
|
2023-08-30 07:28:00 +00:00
|
|
|
},
|
|
|
|
getMenuItemProps(processedItem, index) {
|
|
|
|
return {
|
|
|
|
action: mergeProps(
|
|
|
|
{
|
2024-04-30 13:03:20 +00:00
|
|
|
class: this.cx('itemLink'),
|
2023-08-30 07:28:00 +00:00
|
|
|
tabindex: -1,
|
|
|
|
'aria-hidden': true
|
|
|
|
},
|
2024-04-30 13:03:20 +00:00
|
|
|
this.getPTOptions(processedItem, index, 'itemLink')
|
2023-08-30 07:28:00 +00:00
|
|
|
),
|
|
|
|
icon: mergeProps(
|
|
|
|
{
|
2024-04-30 13:03:20 +00:00
|
|
|
class: [this.cx('itemIcon'), this.getItemProp(processedItem, 'icon')]
|
2023-08-30 07:28:00 +00:00
|
|
|
},
|
2024-04-30 13:03:20 +00:00
|
|
|
this.getPTOptions(processedItem, index, 'itemIcon')
|
2023-08-30 07:28:00 +00:00
|
|
|
),
|
|
|
|
label: mergeProps(
|
|
|
|
{
|
2024-04-30 13:03:20 +00:00
|
|
|
class: this.cx('itemLabel')
|
2023-08-30 07:28:00 +00:00
|
|
|
},
|
2024-04-30 13:03:20 +00:00
|
|
|
this.getPTOptions(processedItem, index, 'itemLabel')
|
2023-08-30 07:28:00 +00:00
|
|
|
),
|
|
|
|
submenuicon: mergeProps(
|
|
|
|
{
|
|
|
|
class: this.cx('submenuIcon')
|
|
|
|
},
|
|
|
|
this.getPTOptions(processedItem, index, 'submenuIcon')
|
|
|
|
)
|
|
|
|
};
|
2023-11-09 14:18:51 +00:00
|
|
|
},
|
|
|
|
containerRef(el) {
|
|
|
|
this.container = el;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
2023-04-05 11:57:18 +00:00
|
|
|
components: {
|
|
|
|
AngleRightIcon: AngleRightIcon
|
|
|
|
},
|
2022-09-06 12:03:37 +00:00
|
|
|
directives: {
|
2022-09-14 11:26:01 +00:00
|
|
|
ripple: Ripple
|
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>
|