Skip to content

Commit

Permalink
fix issue ant-design#9359
Browse files Browse the repository at this point in the history
  • Loading branch information
iammathew committed Feb 15, 2018
1 parent a438b9b commit 207ce65
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
7 changes: 7 additions & 0 deletions components/badge/__tests__/__snapshots__/demo.test.js.snap
Expand Up @@ -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"
>
Expand Down
14 changes: 14 additions & 0 deletions components/badge/__tests__/index.test.js
@@ -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);
});
});
4 changes: 4 additions & 0 deletions components/badge/demo/dot.md
Expand Up @@ -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';
Expand All @@ -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>
Expand Down
7 changes: 3 additions & 4 deletions components/badge/index.tsx
Expand Up @@ -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({
Expand All @@ -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, {
Expand Down

0 comments on commit 207ce65

Please sign in to comment.