fix: children of Tabs[type="editable-card"] cannot be falsy (#17965)

* tabs-editable-card-bugfix

if tabs type ="editable-card",if children has falsy value ,we will get error message,so we should fix it in tabs.

error:https://codesandbox.io/s/lively-glade-jmg5s

* editable-card bugfix

* tabs bugfix

* tabs-editable-card bugfix

* tab bugfix

* bugfix

* delete errorfix

* add test
This commit is contained in:
oldchicken 2019-07-30 16:10:14 +08:00 committed by 偏右
parent facc7124da
commit 5a7a92af46
2 changed files with 30 additions and 25 deletions

View File

@ -16,6 +16,9 @@ describe('Tabs', () => {
<TabPane tab="foo" key="1">
foo
</TabPane>
{undefined}
{null}
{false}
</Tabs>,
);
});
@ -32,6 +35,10 @@ describe('Tabs', () => {
wrapper.find('.anticon-close').simulate('click');
expect(handleEdit).toHaveBeenCalledWith('1', 'remove');
});
it('validateElement', () => {
expect(wrapper.find('.ant-tabs-tab').length).toBe(1);
});
});
describe('tabPosition', () => {

View File

@ -129,31 +129,29 @@ export default class Tabs extends React.Component<TabsProps, any> {
let childrenWithClose: React.ReactElement<any>[] = [];
if (type === 'editable-card') {
childrenWithClose = [];
React.Children.forEach(
children as React.ReactNode,
(child: React.ReactElement<any>, index) => {
let closable = child.props.closable;
closable = typeof closable === 'undefined' ? true : closable;
const closeIcon = closable ? (
<Icon
type="close"
className={`${prefixCls}-close-x`}
onClick={e => this.removeTab(child.key as string, e)}
/>
) : null;
childrenWithClose.push(
React.cloneElement(child, {
tab: (
<div className={closable ? undefined : `${prefixCls}-tab-unclosable`}>
{child.props.tab}
{closeIcon}
</div>
),
key: child.key || index,
}),
);
},
);
React.Children.forEach(children as React.ReactNode, (child, index) => {
if (!React.isValidElement(child)) return child;
let closable = child.props.closable;
closable = typeof closable === 'undefined' ? true : closable;
const closeIcon = closable ? (
<Icon
type="close"
className={`${prefixCls}-close-x`}
onClick={e => this.removeTab(child.key as string, e)}
/>
) : null;
childrenWithClose.push(
React.cloneElement(child, {
tab: (
<div className={closable ? undefined : `${prefixCls}-tab-unclosable`}>
{child.props.tab}
{closeIcon}
</div>
),
key: child.key || index,
}),
);
});
// Add new tab handler
if (!hideAdd) {
tabBarExtraContent = (