fix: Desctiption miss style when value is number 0 (#21901)

* fix: Desctiption miss style when value is number 0

* fix test case
This commit is contained in:
二货机器人 2020-03-05 17:54:58 +08:00 committed by GitHub
parent 3de412353f
commit 4b0effbc0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 3 deletions

View File

@ -1,6 +1,10 @@
import * as React from 'react';
import classNames from 'classnames';
function notEmpty(val: any) {
return val !== undefined && val !== null;
}
export interface CellProps {
itemPrefixCls: string;
span: number;
@ -31,15 +35,15 @@ const Cell: React.FC<CellProps> = ({
<Component
className={classNames(
{
[`${itemPrefixCls}-item-label`]: label,
[`${itemPrefixCls}-item-content`]: content,
[`${itemPrefixCls}-item-label`]: notEmpty(label),
[`${itemPrefixCls}-item-content`]: notEmpty(content),
},
className,
)}
style={style}
colSpan={span}
>
{label || content}
{notEmpty(label) ? label : content}
</Component>
);
}

View File

@ -216,4 +216,15 @@ describe('Descriptions', () => {
matchSpan(2, [2, 2]);
matchSpan(4, [3, 1]);
});
it('number value should render correct', () => {
const wrapper = mount(
<Descriptions bordered>
<Descriptions.Item label={0}>{0}</Descriptions.Item>
</Descriptions>,
);
expect(wrapper.find('th').hasClass('ant-descriptions-item-label')).toBeTruthy();
expect(wrapper.find('td').hasClass('ant-descriptions-item-content')).toBeTruthy();
});
});