feat: update tabs
parent
48f2facb44
commit
a8424d271f
|
@ -63,8 +63,12 @@ export default {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
const panes = this.panes.filter(pane => pane.key !== targetKey)
|
const panes = this.panes.filter(pane => pane.key !== targetKey)
|
||||||
if (lastIndex >= 0 && activeKey === targetKey) {
|
if (panes.length && activeKey === targetKey) {
|
||||||
activeKey = panes[lastIndex].key
|
if (lastIndex >= 0) {
|
||||||
|
activeKey = panes[lastIndex].key;
|
||||||
|
} else {
|
||||||
|
activeKey = panes[0].key;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.panes = panes
|
this.panes = panes
|
||||||
this.activeKey = activeKey
|
this.activeKey = activeKey
|
||||||
|
|
|
@ -59,8 +59,12 @@ export default {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
const panes = this.panes.filter(pane => pane.key !== targetKey)
|
const panes = this.panes.filter(pane => pane.key !== targetKey)
|
||||||
if (lastIndex >= 0 && activeKey === targetKey) {
|
if (panes.length && activeKey === targetKey) {
|
||||||
activeKey = panes[lastIndex].key
|
if (lastIndex >= 0) {
|
||||||
|
activeKey = panes[lastIndex].key;
|
||||||
|
} else {
|
||||||
|
activeKey = panes[0].key;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.panes = panes
|
this.panes = panes
|
||||||
this.activeKey = activeKey
|
this.activeKey = activeKey
|
||||||
|
|
|
@ -5,6 +5,7 @@ import isFlexSupported from '../_util/isFlexSupported';
|
||||||
import PropTypes from '../_util/vue-types';
|
import PropTypes from '../_util/vue-types';
|
||||||
import { getComponentFromProp, getOptionProps, filterEmpty } from '../_util/props-util';
|
import { getComponentFromProp, getOptionProps, filterEmpty } from '../_util/props-util';
|
||||||
import { cloneElement } from '../_util/vnode';
|
import { cloneElement } from '../_util/vnode';
|
||||||
|
import { ConfigConsumerProps } from '../config-provider';
|
||||||
import TabBar from './TabBar';
|
import TabBar from './TabBar';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
@ -15,7 +16,7 @@ export default {
|
||||||
event: 'change',
|
event: 'change',
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
prefixCls: PropTypes.string.def('ant-tabs'),
|
prefixCls: PropTypes.string,
|
||||||
activeKey: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
activeKey: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
||||||
defaultActiveKey: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
defaultActiveKey: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
||||||
hideAdd: PropTypes.bool.def(false),
|
hideAdd: PropTypes.bool.def(false),
|
||||||
|
@ -29,6 +30,9 @@ export default {
|
||||||
tabBarGutter: PropTypes.number,
|
tabBarGutter: PropTypes.number,
|
||||||
renderTabBar: PropTypes.func,
|
renderTabBar: PropTypes.func,
|
||||||
},
|
},
|
||||||
|
inject: {
|
||||||
|
configProvider: { default: () => ({}) },
|
||||||
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
const NO_FLEX = ' no-flex';
|
const NO_FLEX = ' no-flex';
|
||||||
const tabNode = this.$el;
|
const tabNode = this.$el;
|
||||||
|
@ -64,7 +68,7 @@ export default {
|
||||||
render() {
|
render() {
|
||||||
const props = getOptionProps(this);
|
const props = getOptionProps(this);
|
||||||
const {
|
const {
|
||||||
prefixCls,
|
prefixCls: customizePrefixCls,
|
||||||
size,
|
size,
|
||||||
type = 'line',
|
type = 'line',
|
||||||
tabPosition,
|
tabPosition,
|
||||||
|
@ -72,6 +76,8 @@ export default {
|
||||||
hideAdd,
|
hideAdd,
|
||||||
renderTabBar,
|
renderTabBar,
|
||||||
} = props;
|
} = props;
|
||||||
|
const getPrefixCls = this.configProvider.getPrefixCls || ConfigConsumerProps.getPrefixCls;
|
||||||
|
const prefixCls = getPrefixCls('tabs', customizePrefixCls);
|
||||||
const children = filterEmpty(this.$slots.default);
|
const children = filterEmpty(this.$slots.default);
|
||||||
|
|
||||||
let tabBarExtraContent = getComponentFromProp(this, 'tabBarExtraContent');
|
let tabBarExtraContent = getComponentFromProp(this, 'tabBarExtraContent');
|
||||||
|
@ -136,6 +142,7 @@ export default {
|
||||||
const tabBarProps = {
|
const tabBarProps = {
|
||||||
props: {
|
props: {
|
||||||
...this.$props,
|
...this.$props,
|
||||||
|
prefixCls,
|
||||||
tabBarExtraContent,
|
tabBarExtraContent,
|
||||||
renderTabBar: renderTabBarSlot,
|
renderTabBar: renderTabBarSlot,
|
||||||
},
|
},
|
||||||
|
@ -148,6 +155,7 @@ export default {
|
||||||
const tabsProps = {
|
const tabsProps = {
|
||||||
props: {
|
props: {
|
||||||
...getOptionProps(this),
|
...getOptionProps(this),
|
||||||
|
prefixCls,
|
||||||
tabBarPosition: tabPosition,
|
tabBarPosition: tabPosition,
|
||||||
renderTabBar: () => <TabBar {...tabBarProps} />,
|
renderTabBar: () => <TabBar {...tabBarProps} />,
|
||||||
renderTabContent: () => (
|
renderTabContent: () => (
|
||||||
|
|
Loading…
Reference in New Issue