Skip to content

Commit a8424d2

Browse files
committed
feat: update tabs
1 parent 48f2fac commit a8424d2

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

components/tabs/demo/custom-add-trigger.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,12 @@ export default {
6363
}
6464
})
6565
const panes = this.panes.filter(pane => pane.key !== targetKey)
66-
if (lastIndex >= 0 && activeKey === targetKey) {
67-
activeKey = panes[lastIndex].key
66+
if (panes.length && activeKey === targetKey) {
67+
if (lastIndex >= 0) {
68+
activeKey = panes[lastIndex].key;
69+
} else {
70+
activeKey = panes[0].key;
71+
}
6872
}
6973
this.panes = panes
7074
this.activeKey = activeKey

components/tabs/demo/editable-card.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,12 @@ export default {
5959
}
6060
})
6161
const panes = this.panes.filter(pane => pane.key !== targetKey)
62-
if (lastIndex >= 0 && activeKey === targetKey) {
63-
activeKey = panes[lastIndex].key
62+
if (panes.length && activeKey === targetKey) {
63+
if (lastIndex >= 0) {
64+
activeKey = panes[lastIndex].key;
65+
} else {
66+
activeKey = panes[0].key;
67+
}
6468
}
6569
this.panes = panes
6670
this.activeKey = activeKey

components/tabs/tabs.jsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import isFlexSupported from '../_util/isFlexSupported';
55
import PropTypes from '../_util/vue-types';
66
import { getComponentFromProp, getOptionProps, filterEmpty } from '../_util/props-util';
77
import { cloneElement } from '../_util/vnode';
8+
import { ConfigConsumerProps } from '../config-provider';
89
import TabBar from './TabBar';
910

1011
export default {
@@ -15,7 +16,7 @@ export default {
1516
event: 'change',
1617
},
1718
props: {
18-
prefixCls: PropTypes.string.def('ant-tabs'),
19+
prefixCls: PropTypes.string,
1920
activeKey: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
2021
defaultActiveKey: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
2122
hideAdd: PropTypes.bool.def(false),
@@ -29,6 +30,9 @@ export default {
2930
tabBarGutter: PropTypes.number,
3031
renderTabBar: PropTypes.func,
3132
},
33+
inject: {
34+
configProvider: { default: () => ({}) },
35+
},
3236
mounted() {
3337
const NO_FLEX = ' no-flex';
3438
const tabNode = this.$el;
@@ -64,14 +68,16 @@ export default {
6468
render() {
6569
const props = getOptionProps(this);
6670
const {
67-
prefixCls,
71+
prefixCls: customizePrefixCls,
6872
size,
6973
type = 'line',
7074
tabPosition,
7175
animated = true,
7276
hideAdd,
7377
renderTabBar,
7478
} = props;
79+
const getPrefixCls = this.configProvider.getPrefixCls || ConfigConsumerProps.getPrefixCls;
80+
const prefixCls = getPrefixCls('tabs', customizePrefixCls);
7581
const children = filterEmpty(this.$slots.default);
7682

7783
let tabBarExtraContent = getComponentFromProp(this, 'tabBarExtraContent');
@@ -136,6 +142,7 @@ export default {
136142
const tabBarProps = {
137143
props: {
138144
...this.$props,
145+
prefixCls,
139146
tabBarExtraContent,
140147
renderTabBar: renderTabBarSlot,
141148
},
@@ -148,6 +155,7 @@ export default {
148155
const tabsProps = {
149156
props: {
150157
...getOptionProps(this),
158+
prefixCls,
151159
tabBarPosition: tabPosition,
152160
renderTabBar: () => <TabBar {...tabBarProps} />,
153161
renderTabContent: () => (

0 commit comments

Comments
 (0)