Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: Desctiption miss style when value is number 0 (#21901)
* fix: Desctiption miss style when value is number 0

* fix test case
  • Loading branch information
zombieJ committed Mar 5, 2020
1 parent 3de4123 commit 4b0effb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
10 changes: 7 additions & 3 deletions components/descriptions/Cell.tsx
@@ -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;
Expand Down Expand Up @@ -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>
);
}
Expand Down
11 changes: 11 additions & 0 deletions components/descriptions/__tests__/index.test.js
Expand Up @@ -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();
});
});

0 comments on commit 4b0effb

Please sign in to comment.