Reimplement TabView active tab handling
parent
1140ebe31f
commit
6908614ec9
|
@ -5,16 +5,16 @@ export default {
|
|||
active: Boolean,
|
||||
disabled: Boolean
|
||||
},
|
||||
watch: {
|
||||
active(newValue) {
|
||||
this.d_active = newValue;
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
d_active: this.active
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
active(newValue) {
|
||||
this.d_active = newValue;
|
||||
}
|
||||
},
|
||||
render() {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<template>
|
||||
<div class="p-tabview-panel" role="tabpanel" v-show="active">
|
||||
<div class="p-tabview-panel" role="tabpanel" v-show="d_active">
|
||||
<slot></slot>
|
||||
</div>
|
||||
</template>
|
||||
|
@ -8,11 +8,17 @@
|
|||
export default {
|
||||
props: {
|
||||
header: null,
|
||||
active: Boolean,
|
||||
disabled: Boolean
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
active: false
|
||||
d_active: this.active
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
active(newValue) {
|
||||
this.d_active = newValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,63 +1,61 @@
|
|||
<script>
|
||||
export default {
|
||||
props: {
|
||||
activeIndex: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
orientation: {
|
||||
type: String,
|
||||
default: 'top'
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
d_activeTabIndex: this.activeIndex,
|
||||
tabs: []
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
activeIndex(newValue) {
|
||||
this.activateTab(newValue);
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.tabs = this.$children;
|
||||
this.tabs[this.activeIndex].active = true;
|
||||
|
||||
let activeTab = this.findActiveTab();
|
||||
if (!activeTab && this.tabs.length) {
|
||||
this.tabs[0].d_active = true;
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
onTabClick(event, tab, index) {
|
||||
if (!tab.disabled && index !== this.d_activeTabIndex) {
|
||||
this.activateTab(index);
|
||||
onTabClick(event, tab) {
|
||||
if (!tab.disabled && !tab.d_active) {
|
||||
this.activateTab(tab);
|
||||
|
||||
this.$emit('tabchange', {
|
||||
originalEvent: event,
|
||||
tab: tab,
|
||||
index: index
|
||||
tab: tab
|
||||
});
|
||||
}
|
||||
},
|
||||
activateTab(index) {
|
||||
this.d_activeTabIndex = index;
|
||||
activateTab(tab) {
|
||||
for (let i = 0; i < this.tabs.length; i++) {
|
||||
this.tabs[i].active = (i === index);
|
||||
this.tabs[i].d_active = this.tabs[i] === tab;
|
||||
}
|
||||
},
|
||||
onTabKeydown(event, tab, index) {
|
||||
onTabKeydown(event, tab) {
|
||||
if (event.which === 13) {
|
||||
this.onTabClick(event, tab, index);
|
||||
this.onTabClick(event, tab);
|
||||
}
|
||||
},
|
||||
findActiveTab() {
|
||||
let activeTab;
|
||||
for (let i = 0; i < this.tabs.length; i++) {
|
||||
let tab = this.tabs[i];
|
||||
if (tab.d_active) {
|
||||
activeTab = tab;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return activeTab;
|
||||
}
|
||||
},
|
||||
render() {
|
||||
return (
|
||||
<div class="p-tabview p-component p-tabview-top">
|
||||
<ul class="p-tabview-nav p-resest" role="tablist">
|
||||
<ul class="p-tabview-nav p-reset" role="tablist">
|
||||
{
|
||||
this.tabs.map((tab, i) => {
|
||||
this.tabs.map(tab => {
|
||||
return (
|
||||
<li role="presentation" key={tab.header||i} class={{'p-highlight': (this.d_activeTabIndex === i), 'p-disabled': tab.disabled}}>
|
||||
<a role="tab" on-click={event => this.onTabClick(event, tab, i)} on-keydown={event => this.onTabKeydown(event, tab, i)} tabindex={tab.disabled ? null : '0'}>
|
||||
<li role="presentation" key={tab.header} class={['p-unselectable-text', {'p-highlight': (tab.d_active), 'p-disabled': tab.disabled}]}>
|
||||
<a role="tab" on-click={event => this.onTabClick(event, tab)} on-keydown={event => this.onTabKeydown(event, tab)} tabindex={tab.disabled ? null : '0'}>
|
||||
{tab.header && <span class="p-tabview-title">{tab.header}</span>}
|
||||
{tab.$slots.header}
|
||||
</a>
|
||||
|
|
|
@ -28,23 +28,23 @@
|
|||
</p-tabView>
|
||||
|
||||
<h3>Programmatic</h3>
|
||||
<div style="padding: .25em">
|
||||
<div style="padding: .5em 0">
|
||||
<p-button icon="pi pi-chevron-left" @click="prev" class="p-button-secondary" />
|
||||
<p-button icon="pi pi-chevron-right" @click="next" style="margin-left: .5em" class="p-button-secondary"/>
|
||||
</div>
|
||||
|
||||
<p-tabView :activeIndex="activeIndex">
|
||||
<p-tabPanel header="Godfather I">
|
||||
<p-tabView>
|
||||
<p-tabPanel header="Godfather I" :active="activeIndex === 0">
|
||||
The story begins as Don Vito Corleone, the head of a New York Mafia family, overseeshis daughter's wedding. His beloved son ichael has just come home from the war,
|
||||
but does not intend to become part of his father's business. Through Michael's life the nature of the family business becomes clear. The business of the family is
|
||||
just like the head of the family, kind and benevolent to those who give respect, but given to ruthless violence whenever anything stands against the good of the family.
|
||||
</p-tabPanel>
|
||||
<p-tabPanel header="Godfather II">
|
||||
<p-tabPanel header="Godfather II" :active="activeIndex === 1">
|
||||
Francis Ford Coppola's legendary continuation and sequel to his landmark 1972 film, TheGodfather parallels the young Vito Corleone's rise with his son Michael's spiritual fall,
|
||||
deepening The Godfather's depiction of the dark side of the American dream. In the early 1900s, the child Vito flees his Sicilian village for America after the local Mafia kills
|
||||
his family. Vito struggles to make a living, legally or illegally, for his wife and growing brood in Little Italy.
|
||||
</p-tabPanel>
|
||||
<p-tabPanel header="Godfather III">
|
||||
<p-tabPanel header="Godfather III" :active="activeIndex === 2">
|
||||
The Godfather Part III is set in 1979 and 1980. Michael has moved back to New York and taken great strides to remove the family from crime. He turns over his New York criminal
|
||||
interests to longtime enforcer Joey Zasa. He uses his wealth in an attempt to rehabilitate his reputation through numerous philanthropic acts, administered by a foundation named after his father.
|
||||
A decade earlier, he gave custody of his two children to Kay, who has since remarried.
|
||||
|
@ -110,7 +110,7 @@
|
|||
export default {
|
||||
data() {
|
||||
return {
|
||||
activeIndex: 1
|
||||
activeIndex: 0
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
|
Loading…
Reference in New Issue