Refactor #4739 - For Menu

pull/4763/head
tugcekucukoglu 2023-11-08 15:48:47 +03:00
parent 7ffb1452aa
commit be33e737a1
5 changed files with 6 additions and 34 deletions

View File

@ -26,10 +26,6 @@ export default {
type: Number,
default: 0
},
exact: {
type: Boolean,
default: true
},
tabindex: {
type: Number,
default: 0

View File

@ -210,6 +210,7 @@ export interface MenuProps {
baseZIndex?: number | undefined;
/**
* Whether to apply 'router-link-active-exact' class if route exactly matches the item path.
* @deprecated since v3.40.0.
* @defaultValue true
*/
exact?: boolean | undefined;

View File

@ -25,12 +25,12 @@
<slot name="submenuheader" :item="item">{{ label(item) }}</slot>
</li>
<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" :templates="$slots" :exact="exact" :focusedOptionId="focusedOptionId" @item-click="itemClick" :pt="pt" />
<PVMenuitem v-if="visible(child) && !child.separator" :id="id + '_' + i + '_' + j" :item="child" :templates="$slots" :focusedOptionId="focusedOptionId" @item-click="itemClick" :pt="pt" />
<li v-else-if="visible(child) && child.separator" :key="'separator' + i + j" :class="[cx('separator'), item.class]" :style="child.style" role="separator" v-bind="ptm('separator')"></li>
</template>
</template>
<li v-else-if="visible(item) && item.separator" :key="'separator' + i.toString()" :class="[cx('separator'), item.class]" :style="item.style" role="separator" v-bind="ptm('separator')"></li>
<PVMenuitem v-else :key="label(item) + i.toString()" :id="id + '_' + i" :item="item" :index="i" :templates="$slots" :exact="exact" :focusedOptionId="focusedOptionId" @item-click="itemClick" :pt="pt" />
<PVMenuitem v-else :key="label(item) + i.toString()" :id="id + '_' + i" :item="item" :index="i" :templates="$slots" :focusedOptionId="focusedOptionId" @item-click="itemClick" :pt="pt" />
</template>
</ul>
<div v-if="$slots.end" :class="cx('end')" v-bind="ptm('end')">
@ -73,11 +73,6 @@ export default {
resizeListener: null,
container: null,
list: null,
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();
@ -115,10 +110,6 @@ export default {
item.command(event);
}
if (item.to && event.navigate) {
event.navigate(event.originalEvent);
}
if (this.overlayVisible) this.hide();
if (!this.popup && this.focusedOptionIndex !== event.id) {

View File

@ -13,14 +13,7 @@
>
<div :class="cx('content')" @click="onItemClick($event)" v-bind="getPTOptions('content')">
<template v-if="!templates.item">
<router-link v-if="item.to && !disabled()" v-slot="{ navigate, href, isActive, isExactActive }" :to="item.to" custom>
<a v-ripple :href="href" :class="cx('action', { isActive, isExactActive })" tabindex="-1" aria-hidden="true" @click="onItemActionClick($event, navigate)" v-bind="getPTOptions('action')">
<component v-if="templates.itemicon" :is="templates.itemicon" :item="item" :class="[cx('icon'), item.icon]" />
<span v-else-if="item.icon" :class="[cx('icon'), item.icon]" v-bind="getPTOptions('icon')" />
<span :class="cx('label')" v-bind="getPTOptions('label')">{{ label() }}</span>
</a>
</router-link>
<a v-else v-ripple :href="item.url" :class="cx('action')" :target="item.target" tabindex="-1" aria-hidden="true" v-bind="getPTOptions('action')">
<a v-ripple :href="item.url" :class="cx('action')" :target="item.target" tabindex="-1" aria-hidden="true" v-bind="getPTOptions('action')">
<component v-if="templates.itemicon" :is="templates.itemicon" :item="item" :class="[cx('icon'), item.icon]" />
<span v-else-if="item.icon" :class="[cx('icon'), item.icon]" v-bind="getPTOptions('icon')" />
<span :class="cx('label')" v-bind="getPTOptions('label')">{{ label() }}</span>
@ -46,7 +39,7 @@ export default {
props: {
item: null,
templates: null,
exact: null,
id: null,
focusedOptionId: null,
index: null
@ -68,9 +61,6 @@ export default {
isItemFocused() {
return this.focusedOptionId === this.id;
},
onItemActionClick(event, navigate) {
navigate && navigate(event);
},
onItemClick(event) {
const command = this.getItemProp(this.item, 'command');

View File

@ -45,13 +45,7 @@ const classes = {
}
],
content: 'p-menuitem-content',
action: ({ props, isActive, isExactActive }) => [
'p-menuitem-link',
{
'router-link-active': isActive,
'router-link-active-exact': props.exact && isExactActive
}
],
action: 'p-menuitem-link',
icon: 'p-menuitem-icon',
label: 'p-menuitem-text'
};