2022-09-06 12:03:37 +00:00
|
|
|
<template>
|
2023-05-29 09:09:48 +00:00
|
|
|
<li
|
|
|
|
v-if="visible()"
|
|
|
|
:id="id"
|
2024-04-30 13:02:03 +00:00
|
|
|
:class="[cx('item'), item.class]"
|
2023-05-29 09:09:48 +00:00
|
|
|
role="menuitem"
|
|
|
|
:style="item.style"
|
|
|
|
:aria-label="label()"
|
|
|
|
:aria-disabled="disabled()"
|
2024-04-30 13:02:03 +00:00
|
|
|
v-bind="getPTOptions('item')"
|
2023-05-29 09:09:48 +00:00
|
|
|
:data-p-focused="isItemFocused()"
|
|
|
|
:data-p-disabled="disabled() || false"
|
|
|
|
>
|
2024-04-30 13:02:03 +00:00
|
|
|
<div :class="cx('itemContent')" @click="onItemClick($event)" @mousemove="onItemMouseMove($event)" v-bind="getPTOptions('itemContent')">
|
2023-04-17 06:05:55 +00:00
|
|
|
<template v-if="!templates.item">
|
2024-04-30 13:02:03 +00:00
|
|
|
<a v-ripple :href="item.url" :class="cx('itemLink')" :target="item.target" tabindex="-1" aria-hidden="true" v-bind="getPTOptions('itemLink')">
|
|
|
|
<component v-if="templates.itemicon" :is="templates.itemicon" :item="item" :class="cx('itemIcon')" />
|
|
|
|
<span v-else-if="item.icon" :class="[cx('itemIcon'), item.icon]" v-bind="getPTOptions('itemIcon')" />
|
2023-05-30 11:06:57 +00:00
|
|
|
<span :class="cx('label')" 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-08-29 12:28:08 +00:00
|
|
|
<component v-else-if="templates.item" :is="templates.item" :item="item" :label="label()" :props="getMenuItemProps(item)"></component>
|
2022-12-08 11:04:25 +00:00
|
|
|
</div>
|
2022-09-06 12:03:37 +00:00
|
|
|
</li>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2023-05-30 11:06:57 +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';
|
2023-08-29 12:28:08 +00:00
|
|
|
import { mergeProps } from 'vue';
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'Menuitem',
|
2023-07-04 06:29:36 +00:00
|
|
|
hostName: 'Menu',
|
2023-05-30 11:06:57 +00:00
|
|
|
extends: BaseComponent,
|
2022-09-06 12:03:37 +00:00
|
|
|
inheritAttrs: false,
|
2024-02-15 15:57:40 +00:00
|
|
|
emits: ['item-click', 'item-mousemove'],
|
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
|
|
|
id: null,
|
2023-07-25 09:11:23 +00:00
|
|
|
focusedOptionId: null,
|
|
|
|
index: 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-07-25 09:11:23 +00:00
|
|
|
item: this.item,
|
|
|
|
index: this.index,
|
2023-10-17 10:06:59 +00:00
|
|
|
focused: this.isItemFocused(),
|
2023-10-17 15:23:16 +00:00
|
|
|
disabled: this.disabled()
|
2023-04-27 14:16:09 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
isItemFocused() {
|
|
|
|
return this.focusedOptionId === this.id;
|
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
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 });
|
|
|
|
},
|
2024-02-15 15:57:40 +00:00
|
|
|
onItemMouseMove(event) {
|
|
|
|
this.$emit('item-mousemove', { originalEvent: event, item: this.item, id: this.id });
|
|
|
|
},
|
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;
|
2023-08-29 12:28:08 +00:00
|
|
|
},
|
|
|
|
getMenuItemProps(item) {
|
|
|
|
return {
|
|
|
|
action: mergeProps(
|
|
|
|
{
|
2024-04-30 13:02:03 +00:00
|
|
|
class: this.cx('itemLink'),
|
2023-08-29 12:28:08 +00:00
|
|
|
tabindex: '-1',
|
|
|
|
'aria-hidden': true
|
|
|
|
},
|
2024-04-30 13:02:03 +00:00
|
|
|
this.getPTOptions('itemLink')
|
2023-08-29 12:28:08 +00:00
|
|
|
),
|
|
|
|
icon: mergeProps(
|
|
|
|
{
|
2024-04-30 13:02:03 +00:00
|
|
|
class: [this.cx('itemIcon'), item.icon]
|
2023-08-29 12:28:08 +00:00
|
|
|
},
|
2024-04-30 13:02:03 +00:00
|
|
|
this.getPTOptions('itemIcon')
|
2023-08-29 12:28:08 +00:00
|
|
|
),
|
|
|
|
label: mergeProps(
|
|
|
|
{
|
|
|
|
class: this.cx('label')
|
|
|
|
},
|
|
|
|
this.getPTOptions('label')
|
|
|
|
)
|
|
|
|
};
|
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>
|