Fixed #1488 - activeIndex for TabMenu
parent
656e9501d6
commit
2495d6099a
|
@ -10,6 +10,31 @@ const TabMenuProps = [
|
||||||
type: "boolean",
|
type: "boolean",
|
||||||
default: "true",
|
default: "true",
|
||||||
description: "Defines if active route highlight should match the exact route path."
|
description: "Defines if active route highlight should match the exact route path."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "activeIndex",
|
||||||
|
type: "number",
|
||||||
|
default: "0",
|
||||||
|
description: "Active index of menuitem."
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
const TabMenuEvents = [
|
||||||
|
{
|
||||||
|
name: "tab-change",
|
||||||
|
description: "Callback to invoke when an active tab is changed.",
|
||||||
|
arguments: [
|
||||||
|
{
|
||||||
|
name: "event.originalEvent",
|
||||||
|
type: "object",
|
||||||
|
description: "Original event"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "event.index",
|
||||||
|
type: "number",
|
||||||
|
description: "Index of the selected tab"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -25,6 +50,7 @@ module.exports = {
|
||||||
name: "TabMenu",
|
name: "TabMenu",
|
||||||
description: "TabMenu is a navigation component that displays items as tab headers.",
|
description: "TabMenu is a navigation component that displays items as tab headers.",
|
||||||
props: TabMenuProps,
|
props: TabMenuProps,
|
||||||
|
events: TabMenuEvents,
|
||||||
slots: TabMenuSlots
|
slots: TabMenuSlots
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,6 +3,7 @@ import { VNode } from 'vue';
|
||||||
interface TabMenuProps {
|
interface TabMenuProps {
|
||||||
model?: any[];
|
model?: any[];
|
||||||
exact?: boolean;
|
exact?: boolean;
|
||||||
|
activeIndex?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
declare class TabMenu {
|
declare class TabMenu {
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
<router-link v-if="item.to && !disabled(item)" :to="item.to" custom v-slot="{navigate, href, isActive, isExactActive}">
|
<router-link v-if="item.to && !disabled(item)" :to="item.to" custom v-slot="{navigate, href, isActive, isExactActive}">
|
||||||
<li :class="getRouteItemClass(item,isActive,isExactActive)" :style="item.style" v-if="visible(item)" role="tab">
|
<li :class="getRouteItemClass(item,isActive,isExactActive)" :style="item.style" v-if="visible(item)" role="tab">
|
||||||
<template v-if="!$slots.item">
|
<template v-if="!$slots.item">
|
||||||
<a :href="href" class="p-menuitem-link" @click="onItemClick($event, item, navigate)" role="presentation" v-ripple>
|
<a :href="href" class="p-menuitem-link" @click="onItemClick($event, item, i, navigate)" role="presentation" v-ripple>
|
||||||
<span :class="getItemIcon(item)" v-if="item.icon"></span>
|
<span :class="getItemIcon(item)" v-if="item.icon"></span>
|
||||||
<span class="p-menuitem-text">{{item.label}}</span>
|
<span class="p-menuitem-text">{{item.label}}</span>
|
||||||
</a>
|
</a>
|
||||||
|
@ -13,9 +13,9 @@
|
||||||
<component v-else :is="$slots.item" :item="item"></component>
|
<component v-else :is="$slots.item" :item="item"></component>
|
||||||
</li>
|
</li>
|
||||||
</router-link>
|
</router-link>
|
||||||
<li v-else-if="visible(item)" :class="getItemClass(item)" role="tab">
|
<li v-else-if="visible(item)" :class="getItemClass(item, i)" role="tab">
|
||||||
<template v-if="!$slots.item">
|
<template v-if="!$slots.item">
|
||||||
<a :href="item.url" class="p-menuitem-link" :target="item.target" @click="onItemClick($event, item)" role="presentation" :tabindex="disabled(item) ? null : '0'" v-ripple>
|
<a :href="item.url" class="p-menuitem-link" :target="item.target" @click="onItemClick($event, item, i)" role="presentation" :tabindex="disabled(item) ? null : '0'" v-ripple>
|
||||||
<span :class="getItemIcon(item)" v-if="item.icon"></span>
|
<span :class="getItemIcon(item)" v-if="item.icon"></span>
|
||||||
<span class="p-menuitem-text">{{item.label}}</span>
|
<span class="p-menuitem-text">{{item.label}}</span>
|
||||||
</a>
|
</a>
|
||||||
|
@ -34,6 +34,7 @@ import Ripple from 'primevue/ripple';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'TabMenu',
|
name: 'TabMenu',
|
||||||
|
emits: ['update:activeIndex', 'tab-change'],
|
||||||
props: {
|
props: {
|
||||||
model: {
|
model: {
|
||||||
type: Array,
|
type: Array,
|
||||||
|
@ -42,9 +43,18 @@ export default {
|
||||||
exact: {
|
exact: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: true
|
default: true
|
||||||
|
},
|
||||||
|
activeIndex: {
|
||||||
|
type: Number,
|
||||||
|
default: 0
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
timeout: null,
|
timeout: null,
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
d_activeIndex: this.activeIndex
|
||||||
|
}
|
||||||
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.updateInkBar();
|
this.updateInkBar();
|
||||||
},
|
},
|
||||||
|
@ -57,10 +67,13 @@ export default {
|
||||||
watch: {
|
watch: {
|
||||||
$route() {
|
$route() {
|
||||||
this.timeout = setTimeout(() => this.updateInkBar(), 50);
|
this.timeout = setTimeout(() => this.updateInkBar(), 50);
|
||||||
|
},
|
||||||
|
activeIndex(newValue) {
|
||||||
|
this.d_activeIndex = newValue;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
onItemClick(event, item, navigate) {
|
onItemClick(event, item, index, navigate) {
|
||||||
if (this.disabled(item)) {
|
if (this.disabled(item)) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
return;
|
return;
|
||||||
|
@ -76,9 +89,20 @@ export default {
|
||||||
if (item.to && navigate) {
|
if (item.to && navigate) {
|
||||||
navigate(event);
|
navigate(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (index !== this.d_activeIndex) {
|
||||||
|
this.d_activeIndex = index;
|
||||||
|
this.$emit('update:activeIndex', this.d_activeIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.$emit('tab-change', {
|
||||||
|
originalEvent: event,
|
||||||
|
index: index
|
||||||
|
});
|
||||||
},
|
},
|
||||||
getItemClass(item) {
|
getItemClass(item, index) {
|
||||||
return ['p-tabmenuitem', item.class, {
|
return ['p-tabmenuitem', item.class, {
|
||||||
|
'p-highlight': this.d_activeIndex === index,
|
||||||
'p-disabled': this.disabled(item)
|
'p-disabled': this.disabled(item)
|
||||||
}];
|
}];
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue