Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Badge): update cached isDotRef when isHidden #30090

Merged
merged 1 commit into from
Apr 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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