Skip to content

Commit ff9f408

Browse files
committed
fix: tabs keydown event trigger twice #1947
1 parent 1852414 commit ff9f408

File tree

3 files changed

+30
-16
lines changed

3 files changed

+30
-16
lines changed

components/_util/vnode.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { filterEmpty, parseStyleText } from './props-util';
22
import classNames from 'classnames';
3+
import { warning } from '../vc-util/warning';
34

45
export function cloneVNode(vnode, deep) {
56
const componentOptions = vnode.componentOptions;
@@ -62,6 +63,11 @@ export function cloneElement(n, nodeProps = {}, deep) {
6263
return null;
6364
}
6465
const node = cloneVNode(ele, deep);
66+
// 函数式组件不支持clone https://github.com/vueComponent/ant-design-vue/pull/1947
67+
warning(
68+
!(node.fnOptions && node.fnOptions.functional),
69+
`can not use cloneElement for functional component (${node.tag})`,
70+
);
6571
const { props = {}, key, on = {}, children, directives = [] } = nodeProps;
6672
const data = node.data || {};
6773
let cls = {};
@@ -127,10 +133,6 @@ export function cloneElement(n, nodeProps = {}, deep) {
127133
node.data.on = { ...(node.data.on || {}), ...on };
128134
}
129135

130-
if (node.fnOptions && node.fnOptions.functional) {
131-
node.data.on = { ...(node.data.on || {}), ...on };
132-
}
133-
134136
if (key !== undefined) {
135137
node.key = key;
136138
node.data.key = key;

components/tabs/TabBar.jsx

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
11
import Icon from '../icon';
22
import ScrollableInkTabBar from '../vc-tabs/src/ScrollableInkTabBar';
33
import { cloneElement } from '../_util/vnode';
4+
import PropTypes from '../_util/vue-types';
5+
import { getListeners } from '../_util/props-util';
46
const TabBar = {
5-
functional: true,
6-
render(h, context) {
7+
name: 'TabBar',
8+
inheritAttrs: false,
9+
props: {
10+
prefixCls: PropTypes.string,
11+
tabBarStyle: PropTypes.object,
12+
tabBarExtraContent: PropTypes.any,
13+
type: PropTypes.oneOf(['line', 'card', 'editable-card']),
14+
tabPosition: PropTypes.oneOf(['top', 'right', 'bottom', 'left']).def('top'),
15+
tabBarPosition: PropTypes.oneOf(['top', 'right', 'bottom', 'left']),
16+
size: PropTypes.oneOf(['default', 'small', 'large']),
17+
animated: PropTypes.oneOfType([PropTypes.bool, PropTypes.object]),
18+
renderTabBar: PropTypes.func,
19+
panels: PropTypes.array.def([]),
20+
activeKey: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
21+
},
22+
render() {
723
const {
824
tabBarStyle,
925
animated = true,
@@ -13,7 +29,7 @@ const TabBar = {
1329
prefixCls,
1430
type = 'line',
1531
size,
16-
} = context.props;
32+
} = this.$props;
1733
const inkBarAnimated = typeof animated === 'object' ? animated.inkBar : animated;
1834

1935
const isVertical = tabPosition === 'left' || tabPosition === 'right';
@@ -39,14 +55,15 @@ const TabBar = {
3955

4056
const renderProps = {
4157
props: {
42-
...context.props,
58+
...this.$props,
59+
...this.$attrs,
4360
inkBarAnimated,
4461
extraContent: tabBarExtraContent,
4562
prevIcon,
4663
nextIcon,
4764
},
4865
style: tabBarStyle,
49-
on: context.listeners,
66+
on: getListeners(this),
5067
class: cls,
5168
};
5269

@@ -58,7 +75,7 @@ const TabBar = {
5875
RenderTabBar = <ScrollableInkTabBar {...renderProps} />;
5976
}
6077

61-
return cloneElement(RenderTabBar, renderProps);
78+
return cloneElement(RenderTabBar);
6279
},
6380
};
6481

components/tabs/tabs.jsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,7 @@ export default {
2626
defaultActiveKey: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
2727
hideAdd: PropTypes.bool.def(false),
2828
tabBarStyle: PropTypes.object,
29-
tabBarExtraContent: PropTypes.oneOfType([
30-
PropTypes.string,
31-
PropTypes.number,
32-
PropTypes.func,
33-
PropTypes.array,
34-
]),
29+
tabBarExtraContent: PropTypes.any,
3530
destroyInactiveTabPane: PropTypes.bool.def(false),
3631
type: PropTypes.oneOf(['line', 'card', 'editable-card']),
3732
tabPosition: PropTypes.oneOf(['top', 'right', 'bottom', 'left']).def('top'),

0 commit comments

Comments
 (0)