mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-11-30 19:19:26 +08:00
parent
feaf238dfa
commit
947cee4475
@ -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"
|
||||
>
|
||||
|
14
components/badge/__tests__/index.test.js
Normal file
14
components/badge/__tests__/index.test.js
Normal 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);
|
||||
});
|
||||
});
|
@ -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>
|
||||
|
@ -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, {
|
||||
|
Loading…
Reference in New Issue
Block a user