fix tabs bug
parent
f1b6d1d3d1
commit
cbde527457
|
@ -98,7 +98,7 @@ export default {
|
||||||
const tabBarExtraContentStyle = topOrBottom ? { float: 'right' } : {}
|
const tabBarExtraContentStyle = topOrBottom ? { float: 'right' } : {}
|
||||||
let children = contents
|
let children = contents
|
||||||
extraContent = typeof extraContent === 'function' ? extraContent(createElement) : extraContent
|
extraContent = typeof extraContent === 'function' ? extraContent(createElement) : extraContent
|
||||||
|
extraContent = extraContent || this.$slots.extraContent
|
||||||
if (tabsType === 'editable-card' && !hideAdd) {
|
if (tabsType === 'editable-card' && !hideAdd) {
|
||||||
extraContent = (
|
extraContent = (
|
||||||
<span>
|
<span>
|
||||||
|
|
|
@ -5,7 +5,7 @@ import TabContent from './TabContent'
|
||||||
import ScrollableInkTabBar from './ScrollableInkTabBar'
|
import ScrollableInkTabBar from './ScrollableInkTabBar'
|
||||||
function getDefaultActiveKey (t) {
|
function getDefaultActiveKey (t) {
|
||||||
let activeKey
|
let activeKey
|
||||||
t.$slots.default.forEach(({ componentOptions = {}}) => {
|
t.$slots.default && t.$slots.default.forEach(({ componentOptions = {}}) => {
|
||||||
const child = componentOptions.propsData
|
const child = componentOptions.propsData
|
||||||
if (child && !activeKey && !child.disabled) {
|
if (child && !activeKey && !child.disabled) {
|
||||||
activeKey = child.tabKey
|
activeKey = child.tabKey
|
||||||
|
@ -14,7 +14,7 @@ function getDefaultActiveKey (t) {
|
||||||
return activeKey
|
return activeKey
|
||||||
}
|
}
|
||||||
function activeKeyIsValid (t, key) {
|
function activeKeyIsValid (t, key) {
|
||||||
const keys = t.$slots.default.map(({ componentOptions = {}}) => {
|
const keys = t.$slots.default && t.$slots.default.map(({ componentOptions = {}}) => {
|
||||||
const child = componentOptions.propsData
|
const child = componentOptions.propsData
|
||||||
if (child) {
|
if (child) {
|
||||||
return child.tabKey
|
return child.tabKey
|
||||||
|
@ -116,7 +116,7 @@ export default {
|
||||||
getNextActiveKey (next) {
|
getNextActiveKey (next) {
|
||||||
const activeKey = this.stateActiveKey
|
const activeKey = this.stateActiveKey
|
||||||
const children = []
|
const children = []
|
||||||
this.$slots.default.forEach(({ componentOptions = {}}) => {
|
this.$slots.default && this.$slots.default.forEach(({ componentOptions = {}}) => {
|
||||||
const c = componentOptions.propsData
|
const c = componentOptions.propsData
|
||||||
if (c && !c.disabled && c.disabled !== '') {
|
if (c && !c.disabled && c.disabled !== '') {
|
||||||
if (next) {
|
if (next) {
|
||||||
|
@ -154,13 +154,11 @@ export default {
|
||||||
setActiveKey,
|
setActiveKey,
|
||||||
$slots,
|
$slots,
|
||||||
} = this
|
} = this
|
||||||
const hasSlot = !!$slots.default
|
|
||||||
const panels = []
|
const panels = []
|
||||||
if (hasSlot) {
|
|
||||||
$slots.default.forEach(tab => {
|
$slots.default && $slots.default.forEach(tab => {
|
||||||
tab.componentOptions && panels.push(tab.componentOptions.propsData)
|
tab.componentOptions && panels.push(tab.componentOptions.propsData)
|
||||||
})
|
})
|
||||||
}
|
|
||||||
const tabContentProps = {
|
const tabContentProps = {
|
||||||
props: {
|
props: {
|
||||||
...this.tabContentProps,
|
...this.tabContentProps,
|
||||||
|
@ -186,7 +184,11 @@ export default {
|
||||||
style: this.tabBarProps.style || {},
|
style: this.tabBarProps.style || {},
|
||||||
}
|
}
|
||||||
const contents = [
|
const contents = [
|
||||||
<ScrollableInkTabBar {...tabBarProps} />,
|
<ScrollableInkTabBar {...tabBarProps}>
|
||||||
|
{$slots.tabBarExtraContent ? <span slot='extraContent'>
|
||||||
|
{$slots.tabBarExtraContent}
|
||||||
|
</span> : null}
|
||||||
|
</ScrollableInkTabBar>,
|
||||||
<TabContent {...tabContentProps}>
|
<TabContent {...tabContentProps}>
|
||||||
{$slots.default}
|
{$slots.default}
|
||||||
</TabContent>,
|
</TabContent>,
|
||||||
|
|
|
@ -1,9 +1,18 @@
|
||||||
<template>
|
<template>
|
||||||
|
<div>
|
||||||
<Tabs :tabBarExtraContent="operations">
|
<Tabs :tabBarExtraContent="operations">
|
||||||
<TabPane tab="Tab 1" tabKey="1">Content of tab 1</TabPane>
|
<TabPane tab="Tab 1" tabKey="1">Content of tab 1</TabPane>
|
||||||
<TabPane tab="Tab 2" tabKey="2">Content of tab 2</TabPane>
|
<TabPane tab="Tab 2" tabKey="2">Content of tab 2</TabPane>
|
||||||
<TabPane tab="Tab 3" tabKey="3">Content of tab 3</TabPane>
|
<TabPane tab="Tab 3" tabKey="3">Content of tab 3</TabPane>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
|
<Tabs>
|
||||||
|
<TabPane tab="Tab 1" tabKey="1">Content of tab 1</TabPane>
|
||||||
|
<TabPane tab="Tab 2" tabKey="2">Content of tab 2</TabPane>
|
||||||
|
<TabPane tab="Tab 3" tabKey="3">Content of tab 3</TabPane>
|
||||||
|
<AntButton slot="tabBarExtraContent">Extra Action</AntButton>
|
||||||
|
</Tabs>
|
||||||
|
</div>
|
||||||
|
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
import { Tabs, Button } from 'antd'
|
import { Tabs, Button } from 'antd'
|
||||||
|
@ -16,6 +25,7 @@ export default {
|
||||||
components: {
|
components: {
|
||||||
Tabs,
|
Tabs,
|
||||||
TabPane: Tabs.TabPane,
|
TabPane: Tabs.TabPane,
|
||||||
|
AntButton: Button,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -81,8 +81,9 @@ export default {
|
||||||
destroyInactiveTabPane = false,
|
destroyInactiveTabPane = false,
|
||||||
activeKey,
|
activeKey,
|
||||||
defaultActiveKey,
|
defaultActiveKey,
|
||||||
|
$slots,
|
||||||
} = this
|
} = this
|
||||||
const { tabBarExtraContent } = this.$props
|
let { tabBarExtraContent } = this.$props
|
||||||
let { inkBarAnimated, tabPaneAnimated } = typeof animated === 'object' ? { // eslint-disable-line
|
let { inkBarAnimated, tabPaneAnimated } = typeof animated === 'object' ? { // eslint-disable-line
|
||||||
inkBarAnimated: !!animated.inkBar, tabPaneAnimated: !!animated.tabPane,
|
inkBarAnimated: !!animated.inkBar, tabPaneAnimated: !!animated.tabPane,
|
||||||
} : {
|
} : {
|
||||||
|
@ -100,7 +101,9 @@ export default {
|
||||||
[`${prefixCls}-${type}`]: true,
|
[`${prefixCls}-${type}`]: true,
|
||||||
[`${prefixCls}-no-animation`]: !tabPaneAnimated,
|
[`${prefixCls}-no-animation`]: !tabPaneAnimated,
|
||||||
}
|
}
|
||||||
|
tabBarExtraContent = tabBarExtraContent || ((h) => {
|
||||||
|
return h('span', [$slots.tabBarExtraContent])
|
||||||
|
})
|
||||||
const tabBarProps = {
|
const tabBarProps = {
|
||||||
inkBarAnimated,
|
inkBarAnimated,
|
||||||
extraContent: tabBarExtraContent,
|
extraContent: tabBarExtraContent,
|
||||||
|
|
Loading…
Reference in New Issue