From dfaec7f076a3790d0f6ce9d3f18480cfde684b94 Mon Sep 17 00:00:00 2001
From: tangjinzhou <415800467@qq.com>
Date: Fri, 8 Dec 2017 11:46:53 +0800
Subject: [PATCH] fix tabs
---
components/tabs/TabPane.vue | 3 +--
components/tabs/Tabs.vue | 28 +++++++++++++--------
components/tabs/demo/basic.vue | 6 ++---
components/tabs/demo/card-top.vue | 6 ++---
components/tabs/demo/card.vue | 6 ++---
components/tabs/demo/custom-add-trigger.vue | 2 +-
components/tabs/demo/disabled.vue | 6 ++---
components/tabs/demo/editable-card.vue | 2 +-
components/tabs/demo/extra.vue | 12 ++++-----
components/tabs/demo/icon.vue | 22 ++++++++++++++--
components/tabs/demo/position.vue | 6 ++---
components/tabs/demo/size.vue | 6 ++---
components/tabs/demo/slide.vue | 22 ++++++++--------
components/tabs/index.vue | 11 ++++++--
components/tabs/index.zh-CN | 2 +-
components/tabs/utils.js | 6 ++---
16 files changed, 88 insertions(+), 58 deletions(-)
diff --git a/components/tabs/TabPane.vue b/components/tabs/TabPane.vue
index 9575569c8..812c52415 100644
--- a/components/tabs/TabPane.vue
+++ b/components/tabs/TabPane.vue
@@ -12,7 +12,6 @@
export default {
name: 'TabPane',
props: {
- tabKey: [String, Number],
tab: [String, Number, Function],
disabled: Boolean,
closable: Boolean,
@@ -34,7 +33,7 @@ export default {
},
active () {
const { activeKey } = this.$parent
- return activeKey === this.tabKey
+ return activeKey === this.$vnode.key
},
isRender () {
const {
diff --git a/components/tabs/Tabs.vue b/components/tabs/Tabs.vue
index f943d7040..f4a12319e 100644
--- a/components/tabs/Tabs.vue
+++ b/components/tabs/Tabs.vue
@@ -5,19 +5,19 @@ import TabContent from './TabContent'
import ScrollableInkTabBar from './ScrollableInkTabBar'
function getDefaultActiveKey (t) {
let activeKey
- t.$slots.default && t.$slots.default.forEach(({ componentOptions = {}}) => {
+ t.$slots.default && t.$slots.default.forEach(({ componentOptions = {}, key: tabKey }) => {
const child = componentOptions.propsData
if (child && !activeKey && !child.disabled) {
- activeKey = child.tabKey
+ activeKey = tabKey
}
})
return activeKey
}
function activeKeyIsValid (t, key) {
- const keys = t.$slots.default && t.$slots.default.map(({ componentOptions = {}}) => {
+ const keys = t.$slots.default && t.$slots.default.map(({ componentOptions = {}, key: tabKey }) => {
const child = componentOptions.propsData
if (child) {
- return child.tabKey
+ return tabKey
}
})
return key !== undefined && keys.indexOf(key) >= 0
@@ -118,18 +118,19 @@ export default {
getNextActiveKey (next) {
const activeKey = this.stateActiveKey
const children = []
- this.$slots.default && this.$slots.default.forEach(({ componentOptions = {}}) => {
+ this.$slots.default && this.$slots.default.forEach(({ componentOptions = {}, key: tabKey }) => {
const c = componentOptions.propsData
+
if (c && !c.disabled && c.disabled !== '') {
if (next) {
- children.push(c)
+ children.push({ ...c, tabKey })
} else {
- children.unshift(c)
+ children.unshift({ ...c, tabKey })
}
}
})
const length = children.length
- let ret = length && children[0].key
+ let ret = length && children[0].tabKey
children.forEach((child, i) => {
if (child.tabKey === activeKey) {
if (i === length - 1) {
@@ -158,8 +159,15 @@ export default {
} = this
const panels = []
- $slots.default && $slots.default.forEach(tab => {
- tab.componentOptions && panels.push(tab.componentOptions.propsData)
+ $slots.default && $slots.default.forEach(({ componentOptions, key: tabKey }) => {
+ if (componentOptions) {
+ if (componentOptions.propsData.tab === undefined) {
+ componentOptions.propsData.tab = $slots[`tab_${tabKey}`]
+ ? h => h('span', [$slots[`tab_${tabKey}`]])
+ : null
+ }
+ panels.push({ ...componentOptions.propsData, tabKey })
+ }
})
const tabContentProps = {
props: {
diff --git a/components/tabs/demo/basic.vue b/components/tabs/demo/basic.vue
index 5d43ebd68..17da286a4 100644
--- a/components/tabs/demo/basic.vue
+++ b/components/tabs/demo/basic.vue
@@ -1,8 +1,8 @@
- Content of Tab Pane 1
- Content of Tab Pane 2
- Content of Tab Pane 3
+ Content of Tab Pane 1
+ Content of Tab Pane 2
+ Content of Tab Pane 3