Refactor #4351 - For ContextMenu

pull/4356/head
Tuğçe Küçükoğlu 2023-08-30 09:27:36 +03:00
parent 55efc21638
commit 3e59aa18b9
2 changed files with 46 additions and 9 deletions

View File

@ -22,6 +22,7 @@
:level="0" :level="0"
:visible="submenuVisible" :visible="submenuVisible"
:pt="pt" :pt="pt"
:unstyled="unstyled"
@focus="onFocus" @focus="onFocus"
@blur="onBlur" @blur="onBlur"
@keydown="onKeyDown" @keydown="onKeyDown"
@ -78,6 +79,18 @@ export default {
} }
} }
}, },
beforeMount() {
if (!this.$slots.item) {
console.warn('In future versions, vue-router support will be removed. Item templating should be used.');
}
},
mounted() {
this.id = this.id || UniqueComponentId();
if (this.global) {
this.bindDocumentContextMenuListener();
}
},
beforeUnmount() { beforeUnmount() {
this.unbindResizeListener(); this.unbindResizeListener();
this.unbindOutsideClickListener(); this.unbindOutsideClickListener();
@ -90,13 +103,6 @@ export default {
this.target = null; this.target = null;
this.container = null; this.container = null;
}, },
mounted() {
this.id = this.id || UniqueComponentId();
if (this.global) {
this.bindDocumentContextMenuListener();
}
},
methods: { methods: {
getItemProp(item, name) { getItemProp(item, name) {
return item ? ObjectUtils.getItemValue(item[name]) : undefined; return item ? ObjectUtils.getItemValue(item[name]) : undefined;

View File

@ -39,7 +39,7 @@
</template> </template>
</a> </a>
</template> </template>
<component v-else :is="templates.item" :item="processedItem.item"></component> <component v-else :is="templates.item" :item="processedItem.item" :label="processedItem.label" :props="getMenuItemProps()"></component>
</div> </div>
<ContextMenuSub <ContextMenuSub
v-if="isItemVisible(processedItem) && isItemGroup(processedItem)" v-if="isItemVisible(processedItem) && isItemGroup(processedItem)"
@ -53,8 +53,9 @@
:activeItemPath="activeItemPath" :activeItemPath="activeItemPath"
:exact="exact" :exact="exact"
:level="level + 1" :level="level + 1"
:pt="pt"
:visible="isItemActive(processedItem) && isItemGroup(processedItem)" :visible="isItemActive(processedItem) && isItemGroup(processedItem)"
:pt="pt"
:unstyled="unstyled"
@item-click="$emit('item-click', $event)" @item-click="$emit('item-click', $event)"
@item-mouseenter="$emit('item-mouseenter', $event)" @item-mouseenter="$emit('item-mouseenter', $event)"
v-bind="ptm('submenu')" v-bind="ptm('submenu')"
@ -197,6 +198,36 @@ export default {
} else { } else {
this.$refs.container.style.left = itemOuterWidth + 'px'; this.$refs.container.style.left = itemOuterWidth + 'px';
} }
},
getMenuItemProps(processedItem, index) {
return {
action: mergeProps(
{
class: this.cx('action'),
tabindex: -1,
'aria-hidden': true
},
this.getPTOptions('action', processedItem, index)
),
icon: mergeProps(
{
class: [this.cx('icon'), this.getItemProp(processedItem, 'icon')]
},
this.getPTOptions('icon', processedItem, index)
),
label: mergeProps(
{
class: this.cx('label')
},
this.getPTOptions('label', processedItem, index)
),
submenuicon: mergeProps(
{
class: this.cx('submenuIcon')
},
this.getPTOptions('submenuicon', processedItem, index)
)
};
} }
}, },
components: { components: {