pull/9/head
tjz 2018-01-21 11:52:34 +08:00
parent 7f083cb99c
commit c328718acb
3 changed files with 20 additions and 6 deletions

View File

@ -79,6 +79,9 @@ export function getComponentName (opts) {
export function isValidElement (ele) { export function isValidElement (ele) {
return !!ele.tag return !!ele.tag
} }
export function isEmptyElement (ele) {
return !(ele.tag || ele.text.trim() !== '')
}
export function getClass (ele) { export function getClass (ele) {
return ele.data && (ele.data.class || ele.data.staticClass) return ele.data && (ele.data.class || ele.data.staticClass)

View File

@ -136,7 +136,7 @@ export default {
renderCommonMenuItem (child, i, subIndex, extraProps) { renderCommonMenuItem (child, i, subIndex, extraProps) {
if (child.tag === undefined) { return child } if (child.tag === undefined) { return child }
warning((getComponentName(child.componentOptions) || '').indexOf(['MenuItem', 'MenuItemGroup']) === -1, warning((getComponentName(child.componentOptions) || '').indexOf(['MenuItem', 'MenuItemGroup']) === -1,
'`Menu child just support MenuItem and MenuItemGroup', '`Menu children just support MenuItem and MenuItemGroup',
) )
const state = this.$data const state = this.$data
const props = this.$props const props = this.$props

View File

@ -2,6 +2,8 @@
import Tabs from './src/Tabs' import Tabs from './src/Tabs'
import isFlexSupported from '../_util/isFlexSupported' import isFlexSupported from '../_util/isFlexSupported'
import { hasProp, getComponentFromProp } from '../_util/props-util' import { hasProp, getComponentFromProp } from '../_util/props-util'
import { getComponentName, isEmptyElement } from '../_util/vnode'
import warning from '../_util/warning'
export default { export default {
props: { props: {
prefixCls: { type: String, default: 'ant-tabs' }, prefixCls: { type: String, default: 'ant-tabs' },
@ -103,11 +105,20 @@ export default {
[`${prefixCls}-no-animation`]: !tabPaneAnimated, [`${prefixCls}-no-animation`]: !tabPaneAnimated,
} }
const tabBarExtraContent = getComponentFromProp(this, 'tabBarExtraContent') const tabBarExtraContent = getComponentFromProp(this, 'tabBarExtraContent')
$slots.default && $slots.default.forEach(({ componentOptions, key: tabKey }) => { const children = []
if (componentOptions && componentOptions.propsData.tab === undefined) { $slots.default && $slots.default.forEach((child) => {
if (isEmptyElement(child)) { return }
const { componentOptions } = child
const componentName = getComponentName(componentOptions)
warning(componentName === 'TabPane', '`Tabs children just support TabPane')
if (componentOptions && componentName === 'TabPane') {
componentOptions.propsData = componentOptions.propsData || {}
if (componentOptions.propsData.tab === undefined) {
const tab = (componentOptions.children || []).filter(({ data = {}}) => data.slot === 'tab') const tab = (componentOptions.children || []).filter(({ data = {}}) => data.slot === 'tab')
componentOptions.propsData.tab = tab componentOptions.propsData.tab = tab
} }
children.push(child)
}
}) })
const tabBarProps = { const tabBarProps = {
props: { props: {
@ -152,7 +163,7 @@ export default {
class={cls} class={cls}
{...tabsProps} {...tabsProps}
> >
{this.$slots.default} {children}
{tabBarExtraContent ? <template slot='tabBarExtraContent'> {tabBarExtraContent ? <template slot='tabBarExtraContent'>
{tabBarExtraContent} {tabBarExtraContent}
</template> : null} </template> : null}