Skip to content

Commit

Permalink
fix(Badge): update cached isDotRef when isHidden
Browse files Browse the repository at this point in the history
  • Loading branch information
jameslahm committed Apr 11, 2021
1 parent aa9fac4 commit c708f2a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
13 changes: 13 additions & 0 deletions components/badge/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,19 @@ describe('Badge', () => {

expect(wrapper.find('.ant-badge')).toHaveLength(2);
});

it('Badge should work when status changes', () => {
const wrapper = mount(
<Badge status="warning">
<button type="button">Click me</button>
</Badge>,
);
wrapper.setProps({ status: undefined });

expect(wrapper.find('.ant-badge-count')).toHaveLength(0);
expect(wrapper.find('.ant-badge-dot')).toHaveLength(0);
expect(wrapper.find('.ant-badge-count-sm')).toHaveLength(0);
});
});

describe('Ribbon', () => {
Expand Down
6 changes: 4 additions & 2 deletions components/badge/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ const Badge: CompoundedComponent = ({
const isDotRef = useRef(showAsDot);
if (!isHidden) {
isDotRef.current = showAsDot;
} else {
isDotRef.current = false;
}

// =============================== Styles ===============================
Expand Down Expand Up @@ -186,8 +188,8 @@ const Badge: CompoundedComponent = ({

const scrollNumberCls = classNames({
[`${prefixCls}-dot`]: isDot,
[`${prefixCls}-count`]: !isDot,
[`${prefixCls}-count-sm`]: size === 'small',
[`${prefixCls}-count`]: !isDot && !isHidden,
[`${prefixCls}-count-sm`]: !isDot && !isHidden && size === 'small',
[`${prefixCls}-multiple-words`]:
!isDot && displayCount && displayCount?.toString().length > 1,
[`${prefixCls}-status-${status}`]: !!status,
Expand Down

0 comments on commit c708f2a

Please sign in to comment.