* fix issue #9359

* fix trailing whitespaces
This commit is contained in:
Mathew 2018-02-24 04:40:44 +01:00 committed by 偏右
parent feaf238dfa
commit 947cee4475
4 changed files with 28 additions and 4 deletions

View File

@ -423,6 +423,13 @@ exports[`renders ./components/badge/demo/dot.md correctly 1`] = `
data-show="true"
/>
</span>
<span
class="ant-badge"
>
<i
class="anticon anticon-notification"
/>
</span>
<span
class="ant-badge"
>

View File

@ -0,0 +1,14 @@
import React from 'react';
import { mount } from 'enzyme';
import Badge from '../index';
describe('Badge', () => {
test('badge dot not scaling count > 9', () => {
const badge = mount(<Badge count={10} dot />);
expect(badge.find('.ant-card-multiple-words').length).toBe(0);
});
test('badge dot not showing count == 0', () => {
const badge = mount(<Badge count={0} dot />);
expect(badge.find('.ant-badge-dot').length).toBe(0);
});
});

View File

@ -12,6 +12,7 @@ title:
## en-US
This will simply display a red badge, without a specific count.
If count equals 0, it won't display the dot.
````jsx
import { Badge, Icon } from 'antd';
@ -21,6 +22,9 @@ ReactDOM.render(
<Badge dot>
<Icon type="notification" />
</Badge>
<Badge count={0} dot>
<Icon type="notification" />
</Badge>
<Badge dot>
<a href="#">Link something</a>
</Badge>

View File

@ -59,14 +59,13 @@ export default class Badge extends React.Component<BadgeProps, any> {
offset,
...restProps,
} = this.props;
const isDot = dot || status;
let displayCount = (count as number) > (overflowCount as number) ? `${overflowCount}+` : count;
const isZero = displayCount === '0' || displayCount === 0;
const isDot = (dot && !isZero) || status;
// dot mode don't need count
if (isDot) {
displayCount = '';
}
const isZero = displayCount === '0' || displayCount === 0;
const isEmpty = displayCount === null || displayCount === undefined || displayCount === '';
const hidden = (isEmpty || (isZero && !showZero)) && !isDot;
const statusCls = classNames({
@ -76,7 +75,7 @@ export default class Badge extends React.Component<BadgeProps, any> {
const scrollNumberCls = classNames({
[`${prefixCls}-dot`]: isDot,
[`${prefixCls}-count`]: !isDot,
[`${prefixCls}-multiple-words`]: count && count.toString && count.toString().length > 1,
[`${prefixCls}-multiple-words`]: !isDot && count && count.toString && count.toString().length > 1,
[`${prefixCls}-status-${status}`]: !!status,
});
const badgeCls = classNames(className, prefixCls, {