Refactor #4739 - For Menu
parent
7ffb1452aa
commit
be33e737a1
|
@ -26,10 +26,6 @@ export default {
|
||||||
type: Number,
|
type: Number,
|
||||||
default: 0
|
default: 0
|
||||||
},
|
},
|
||||||
exact: {
|
|
||||||
type: Boolean,
|
|
||||||
default: true
|
|
||||||
},
|
|
||||||
tabindex: {
|
tabindex: {
|
||||||
type: Number,
|
type: Number,
|
||||||
default: 0
|
default: 0
|
||||||
|
|
|
@ -210,6 +210,7 @@ export interface MenuProps {
|
||||||
baseZIndex?: number | undefined;
|
baseZIndex?: number | undefined;
|
||||||
/**
|
/**
|
||||||
* Whether to apply 'router-link-active-exact' class if route exactly matches the item path.
|
* Whether to apply 'router-link-active-exact' class if route exactly matches the item path.
|
||||||
|
* @deprecated since v3.40.0.
|
||||||
* @defaultValue true
|
* @defaultValue true
|
||||||
*/
|
*/
|
||||||
exact?: boolean | undefined;
|
exact?: boolean | undefined;
|
||||||
|
|
|
@ -25,12 +25,12 @@
|
||||||
<slot name="submenuheader" :item="item">{{ label(item) }}</slot>
|
<slot name="submenuheader" :item="item">{{ label(item) }}</slot>
|
||||||
</li>
|
</li>
|
||||||
<template v-for="(child, j) of item.items" :key="child.label + i + '_' + j">
|
<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>
|
<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>
|
||||||
</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>
|
<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>
|
</template>
|
||||||
</ul>
|
</ul>
|
||||||
<div v-if="$slots.end" :class="cx('end')" v-bind="ptm('end')">
|
<div v-if="$slots.end" :class="cx('end')" v-bind="ptm('end')">
|
||||||
|
@ -73,11 +73,6 @@ export default {
|
||||||
resizeListener: null,
|
resizeListener: null,
|
||||||
container: null,
|
container: null,
|
||||||
list: 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() {
|
mounted() {
|
||||||
this.id = this.id || UniqueComponentId();
|
this.id = this.id || UniqueComponentId();
|
||||||
|
|
||||||
|
@ -115,10 +110,6 @@ export default {
|
||||||
item.command(event);
|
item.command(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.to && event.navigate) {
|
|
||||||
event.navigate(event.originalEvent);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.overlayVisible) this.hide();
|
if (this.overlayVisible) this.hide();
|
||||||
|
|
||||||
if (!this.popup && this.focusedOptionIndex !== event.id) {
|
if (!this.popup && this.focusedOptionIndex !== event.id) {
|
||||||
|
|
|
@ -13,14 +13,7 @@
|
||||||
>
|
>
|
||||||
<div :class="cx('content')" @click="onItemClick($event)" v-bind="getPTOptions('content')">
|
<div :class="cx('content')" @click="onItemClick($event)" v-bind="getPTOptions('content')">
|
||||||
<template v-if="!templates.item">
|
<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="item.url" :class="cx('action')" :target="item.target" tabindex="-1" aria-hidden="true" v-bind="getPTOptions('action')">
|
||||||
<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')">
|
|
||||||
<component v-if="templates.itemicon" :is="templates.itemicon" :item="item" :class="[cx('icon'), item.icon]" />
|
<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 v-else-if="item.icon" :class="[cx('icon'), item.icon]" v-bind="getPTOptions('icon')" />
|
||||||
<span :class="cx('label')" v-bind="getPTOptions('label')">{{ label() }}</span>
|
<span :class="cx('label')" v-bind="getPTOptions('label')">{{ label() }}</span>
|
||||||
|
@ -46,7 +39,7 @@ export default {
|
||||||
props: {
|
props: {
|
||||||
item: null,
|
item: null,
|
||||||
templates: null,
|
templates: null,
|
||||||
exact: null,
|
|
||||||
id: null,
|
id: null,
|
||||||
focusedOptionId: null,
|
focusedOptionId: null,
|
||||||
index: null
|
index: null
|
||||||
|
@ -68,9 +61,6 @@ export default {
|
||||||
isItemFocused() {
|
isItemFocused() {
|
||||||
return this.focusedOptionId === this.id;
|
return this.focusedOptionId === this.id;
|
||||||
},
|
},
|
||||||
onItemActionClick(event, navigate) {
|
|
||||||
navigate && navigate(event);
|
|
||||||
},
|
|
||||||
onItemClick(event) {
|
onItemClick(event) {
|
||||||
const command = this.getItemProp(this.item, 'command');
|
const command = this.getItemProp(this.item, 'command');
|
||||||
|
|
||||||
|
|
|
@ -45,13 +45,7 @@ const classes = {
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
content: 'p-menuitem-content',
|
content: 'p-menuitem-content',
|
||||||
action: ({ props, isActive, isExactActive }) => [
|
action: 'p-menuitem-link',
|
||||||
'p-menuitem-link',
|
|
||||||
{
|
|
||||||
'router-link-active': isActive,
|
|
||||||
'router-link-active-exact': props.exact && isExactActive
|
|
||||||
}
|
|
||||||
],
|
|
||||||
icon: 'p-menuitem-icon',
|
icon: 'p-menuitem-icon',
|
||||||
label: 'p-menuitem-text'
|
label: 'p-menuitem-text'
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue