2022-09-06 12:03:37 +00:00
|
|
|
<template>
|
2023-04-27 14:52:22 +00:00
|
|
|
<li v-if="visible()" :id="id" :class="containerClass()" role="menuitem" :style="item.style" :aria-label="label()" :aria-disabled="disabled()" v-bind="getPTOptions('menuitem')">
|
|
|
|
<div class="p-menuitem-content" @click="onItemClick($event)" v-bind="getPTOptions('content')">
|
2023-04-17 06:05:55 +00:00
|
|
|
<template v-if="!templates.item">
|
2022-12-08 11:04:25 +00:00
|
|
|
<router-link v-if="item.to && !disabled()" v-slot="{ navigate, href, isActive, isExactActive }" :to="item.to" custom>
|
2023-04-27 14:52:22 +00:00
|
|
|
<a v-ripple :href="href" :class="linkClass({ isActive, isExactActive })" tabindex="-1" aria-hidden="true" @click="onItemActionClick($event, navigate)" v-bind="getPTOptions('action')">
|
2023-04-18 10:50:13 +00:00
|
|
|
<component v-if="templates.itemicon" :is="templates.itemicon" :item="item" :class="iconClass" />
|
2023-04-27 14:52:22 +00:00
|
|
|
<span v-else-if="item.icon" :class="iconClass" v-bind="getPTOptions('icon')" />
|
|
|
|
<span class="p-menuitem-text" v-bind="getPTOptions('label')">{{ label() }}</span>
|
2022-12-08 11:04:25 +00:00
|
|
|
</a>
|
|
|
|
</router-link>
|
2023-04-27 14:52:22 +00:00
|
|
|
<a v-else v-ripple :href="item.url" :class="linkClass()" :target="item.target" tabindex="-1" aria-hidden="true" v-bind="getPTOptions('action')">
|
2023-04-18 10:50:13 +00:00
|
|
|
<component v-if="templates.itemicon" :is="templates.itemicon" :item="item" :class="iconClass" />
|
2023-04-27 14:52:22 +00:00
|
|
|
<span v-else-if="item.icon" :class="iconClass" v-bind="getPTOptions('icon')" />
|
|
|
|
<span class="p-menuitem-text" v-bind="getPTOptions('label')">{{ label() }}</span>
|
2022-09-06 12:03:37 +00:00
|
|
|
</a>
|
2022-12-08 11:04:25 +00:00
|
|
|
</template>
|
2023-04-17 06:05:55 +00:00
|
|
|
<component v-else :is="templates.item" :item="item"></component>
|
2022-12-08 11:04:25 +00:00
|
|
|
</div>
|
2022-09-06 12:03:37 +00:00
|
|
|
</li>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2023-04-26 09:58:05 +00:00
|
|
|
import BaseComponent from 'primevue/basecomponent';
|
2022-09-06 12:03:37 +00:00
|
|
|
import Ripple from 'primevue/ripple';
|
2022-12-08 11:04:25 +00:00
|
|
|
import { ObjectUtils } from 'primevue/utils';
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'Menuitem',
|
2023-04-26 09:58:05 +00:00
|
|
|
extends: BaseComponent,
|
2022-09-06 12:03:37 +00:00
|
|
|
inheritAttrs: false,
|
2022-12-08 11:04:25 +00:00
|
|
|
emits: ['item-click'],
|
2022-09-06 12:03:37 +00:00
|
|
|
props: {
|
|
|
|
item: null,
|
2023-04-17 06:05:55 +00:00
|
|
|
templates: null,
|
2022-12-08 11:04:25 +00:00
|
|
|
exact: null,
|
|
|
|
id: null,
|
|
|
|
focusedOptionId: null
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
methods: {
|
2022-12-08 11:04:25 +00:00
|
|
|
getItemProp(processedItem, name) {
|
|
|
|
return processedItem && processedItem.item ? ObjectUtils.getItemValue(processedItem.item[name]) : undefined;
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
2023-04-27 14:16:09 +00:00
|
|
|
getPTOptions(key) {
|
|
|
|
return this.ptm(key, {
|
2023-04-28 10:15:44 +00:00
|
|
|
context: {
|
2023-04-27 14:16:09 +00:00
|
|
|
focused: this.isItemFocused()
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
isItemFocused() {
|
|
|
|
return this.focusedOptionId === this.id;
|
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
onItemActionClick(event, navigate) {
|
|
|
|
navigate && navigate(event);
|
|
|
|
},
|
|
|
|
onItemClick(event) {
|
|
|
|
const command = this.getItemProp(this.item, 'command');
|
|
|
|
|
|
|
|
command && command({ originalEvent: event, item: this.item.item });
|
|
|
|
this.$emit('item-click', { originalEvent: event, item: this.item, id: this.id });
|
|
|
|
},
|
|
|
|
containerClass() {
|
|
|
|
return ['p-menuitem', this.item.class, { 'p-focus': this.id === this.focusedOptionId, 'p-disabled': this.disabled() }];
|
|
|
|
},
|
|
|
|
linkClass(routerProps) {
|
2022-09-14 11:26:01 +00:00
|
|
|
return [
|
|
|
|
'p-menuitem-link',
|
|
|
|
{
|
|
|
|
'router-link-active': routerProps && routerProps.isActive,
|
|
|
|
'router-link-active-exact': this.exact && routerProps && routerProps.isExactActive
|
|
|
|
}
|
|
|
|
];
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
visible() {
|
2022-09-14 11:26:01 +00:00
|
|
|
return typeof this.item.visible === 'function' ? this.item.visible() : this.item.visible !== false;
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
disabled() {
|
|
|
|
return typeof this.item.disabled === 'function' ? this.item.disabled() : this.item.disabled;
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
label() {
|
2022-09-14 11:26:01 +00:00
|
|
|
return typeof this.item.label === 'function' ? this.item.label() : this.item.label;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
2023-04-17 06:05:55 +00:00
|
|
|
computed: {
|
|
|
|
iconClass() {
|
|
|
|
return ['p-menuitem-icon', this.item.icon];
|
|
|
|
}
|
|
|
|
},
|
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>
|