diff --git a/src/components/tabpanel/TabPanel.vue b/src/components/tabpanel/TabPanel.vue index e9cd4745f..badfadbd8 100755 --- a/src/components/tabpanel/TabPanel.vue +++ b/src/components/tabpanel/TabPanel.vue @@ -1,7 +1,5 @@ \ No newline at end of file diff --git a/src/components/tabview/TabView.vue b/src/components/tabview/TabView.vue index 5f3ad675f..cbd3d3591 100755 --- a/src/components/tabview/TabView.vue +++ b/src/components/tabview/TabView.vue @@ -1,16 +1,18 @@ @@ -19,84 +21,63 @@ import DomHandler from '../utils/DomHandler'; import Ripple from '../ripple/Ripple'; -const TabPanelHeaderSlot = { - functional: true, +export default { props: { - tab: { - type: null, - default: null + activeIndex: { + type: Number, + default: 0 } }, - render(createElement, context) { - return [context.props.tab.$scopedSlots['header']()]; - } -}; - -export default { data() { return { - d_children: [] - }; + d_activeIndex: this.activeIndex + } }, - mounted() { - this.d_children = this.$children; + watch: { + activeIndex(newValue) { + this.d_activeIndex = newValue; + } }, updated() { - let activeTab = this.tabs[this.findActiveTabIndex()]; - if (!activeTab && this.tabs.length) { - this.tabs[0].d_active = true; - } + this.updateInkBar(); + }, + mounted() { this.updateInkBar(); }, methods: { - onTabClick(event, tab) { - if (!tab.disabled && !tab.d_active) { - this.activateTab(tab); + onTabClick(event, i) { + if (!this.isTabDisabled(this.tabs[i]) && i !== this.d_activeIndex) { + this.d_activeIndex = i; + this.$emit('update:activeIndex', this.d_activeIndex); this.$emit('tab-change', { originalEvent: event, - tab: tab + index: i }); } }, - activateTab(tab) { - for (let i = 0; i < this.tabs.length; i++) { - let active = this.tabs[i] === tab; - this.tabs[i].d_active = active; - this.tabs[i].$emit('update:active', active); - } - - this.updateInkBar(); - }, - onTabKeydown(event, tab) { + onTabKeydown(event, i) { if (event.which === 13) { - this.onTabClick(event, tab); + this.onTabClick(event, i); } }, - findActiveTabIndex() { - for (let i = 0; i < this.tabs.length; i++) { - let tab = this.tabs[i]; - if (tab.d_active) { - return i; - } - } - - return null; - }, updateInkBar() { - let tabHeader = this.$refs.nav.children[this.findActiveTabIndex()]; + let tabHeader = this.$refs.nav.children[this.d_activeIndex]; this.$refs.inkbar.style.width = DomHandler.getWidth(tabHeader) + 'px'; this.$refs.inkbar.style.left = DomHandler.getOffset(tabHeader).left - DomHandler.getOffset(this.$refs.nav).left + 'px'; + }, + getKey(tab, i) { + return tab.props && tab.props.header ? tab.props.header : i; + }, + isTabDisabled(tab) { + return tab.props && tab.props.disabled; } }, computed: { tabs() { - return this.d_children.filter(child => child.$vnode.tag.indexOf('tabpanel') !== -1); + return this.$slots.default().filter(child => child.type.name === 'tabpanel'); } }, - components: { - 'TabPanelHeaderSlot': TabPanelHeaderSlot - }, directives: { 'ripple': Ripple } diff --git a/src/views/tabview/TabViewDemo.vue b/src/views/tabview/TabViewDemo.vue index e7acfb8cf..e53b91563 100755 --- a/src/views/tabview/TabViewDemo.vue +++ b/src/views/tabview/TabViewDemo.vue @@ -31,24 +31,24 @@
Programmatic
-
-
- - + +

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

- +

Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Consectetur, adipisci velit, sed quia non numquam eius modi.

- +

At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus.

@@ -124,7 +124,7 @@ import EventBus from '@/EventBus'; export default { data() { return { - active: [true, false, false] + active: 0 } }, timeout: null, @@ -142,15 +142,6 @@ export default { clearTimeout(this.timeout); EventBus.off('change-theme'); }, - methods: { - activate(index) { - let activeArray = [...this.active]; - for (let i = 0 ; i < activeArray.length; i++) { - activeArray[i] = (i === index); - } - this.active = activeArray; - } - }, components: { 'TabViewDoc': TabViewDoc } diff --git a/src/views/tabview/TabViewDoc.vue b/src/views/tabview/TabViewDoc.vue index 0e84e104b..e83dfedfa 100755 --- a/src/views/tabview/TabViewDoc.vue +++ b/src/views/tabview/TabViewDoc.vue @@ -25,13 +25,13 @@ import TabPanel from 'primevue/tabpanel';
Active
-

Visibility of the content is specified with the active property that supports one or two-way binding.

+

Visibility of the content is specified with the activeIndex property that supports one or two-way binding.

-<TabView> +<TabView :activeIndex="activeIndex"> <TabPanel header="Header I"> Content I </TabPanel> - <TabPanel header="Header II" :active="true"> + <TabPanel header="Header II"> Content II </TabPanel> <TabPanel header="Header III"> @@ -40,16 +40,16 @@ import TabPanel from 'primevue/tabpanel'; </TabView> -

Two-way binding requires the sync operator.

+

Two-way binding requires v-model.

-<TabView> - <TabPanel header="Header I" :active.sync="active1"> +<TabView v-model:activeIndex="activeIndex"> + <TabPanel header="Header I"> Content I </TabPanel> - <TabPanel header="Header II" :active.sync="active2"> + <TabPanel header="Header II"> Content II </TabPanel> - <TabPanel header="Header III" :active.sync="active3"> + <TabPanel header="Header III""> Content III </TabPanel> </TabView> @@ -74,7 +74,7 @@ import TabPanel from 'primevue/tabpanel';
Header Template

Custom content for the title section of a panel is defined using the header template.

-<TabView class="tabview-custom"> +<TabView> <TabPanel> <template #header> <i class="pi pi-calendar"></i> @@ -95,11 +95,11 @@ import TabPanel from 'primevue/tabpanel';
Programmatic Control

Tabs can be controlled programmatically using active property that defines the active tab.

-<Button @click="activate(0)" class="p-button-text" label="Activate 1st" /> -<Button @click="activate(1)" class="p-button-text" label="Activate 2st" /> -<Button @click="activate(2)" class="p-button-text" label="Activate 3st" /> +<Button @click="active = 0" class="p-button-text" label="Activate 1st" /> +<Button @click="active = 1" class="p-button-text" label="Activate 2nd" /> +<Button @click="active = 2" class="p-button-text" label="Activate 3rd" /> -<TabView> +<TabView v-model:activeIndex="active"> <TabPanel header="Header I" :active.sync="active[0]"> Content I </TabPanel> @@ -117,18 +117,9 @@ import TabPanel from 'primevue/tabpanel'; export default { data() { return { - active: [true, false, false] + active: 0 } - }, - methods: { - activate(index) { - let activeArray = [...this.active]; - for (let i = 0 ; i < activeArray.length; i++) { - activeArray[i] = (i === index); - } - this.active = activeArray; - } - }, + } } @@ -136,32 +127,26 @@ export default {
- - - - - - + + + + + + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + +
NameTypeDefaultDescription
NameTypeDefaultDescription
headerstringnullOrientation of tab headers.
activebooleannullVisibility of the content.
disabledbooleannullWhether the tab is disabled.
headerstringnullOrientation of tab headers.
disabledbooleannullWhether the tab is disabled.
@@ -259,24 +244,24 @@ export default { <div class="card"> <h5>Programmatic</h5> - <div style="padding: .5rem 0 1rem 0"> - <Button @click="activate(0)" class="p-button-text" label="Activate 1st" /> - <Button @click="activate(1)" class="p-button-text" label="Activate 2nd" /> - <Button @click="activate(2)" class="p-button-text" label="Activate 3rd" /> + <div style="padding: .5rem 0 1rem 0" class="p-t-2 p-b-3"> + <Button @click="active = 0" class="p-button-text" label="Activate 1st" /> + <Button @click="active = 1" class="p-button-text" label="Activate 2nd" /> + <Button @click="active = 2" class="p-button-text" label="Activate 3rd" /> </div> - <TabView> - <TabPanel header="Header I" :active.sync="active[0]"> + <TabView ref="tabview2" v-model:activeIndex="active"> + <TabPanel header="Header I"> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> </TabPanel> - <TabPanel header="Header II" :active.sync="active[1]"> + <TabPanel header="Header II"> <p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Consectetur, adipisci velit, sed quia non numquam eius modi.</p> </TabPanel> - <TabPanel header="Header III" :active.sync="active[2]"> + <TabPanel header="Header III"> <p>At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus.</p> @@ -346,18 +331,10 @@ export default { export default { data() { return { - active: [true, false, false] - } - }, - methods: { - activate(index) { - let activeArray = [...this.active]; - for (let i = 0 ; i < activeArray.length; i++) { - activeArray[i] = (i === index); - } - this.active = activeArray; + active: 0 } } +}