mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-01 03:29:39 +08:00
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:
parent
facc7124da
commit
5a7a92af46
@ -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', () => {
|
||||
|
@ -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 = (
|
||||
|
Loading…
Reference in New Issue
Block a user