Skip to content

Commit ee8cc27

Browse files
authored
fix: Badge ref not working (ant-design#56532)
1 parent 6c5036e commit ee8cc27

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

components/badge/Badge.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ const Badge = React.forwardRef<HTMLSpanElement, BadgeProps>((props, ref) => {
211211
const statusTextColor = mergedStyle.color;
212212
return (
213213
<span
214+
ref={ref}
214215
{...restProps}
215216
className={badgeClassName}
216217
style={{ ...mergedStyles.root, ...mergedStyle }}

components/badge/__tests__/index.test.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,4 +240,10 @@ describe('Badge', () => {
240240
rerender(<Badge count={0} showZero color="#ff0" />);
241241
expect(container.querySelectorAll('[title="0"]')).toHaveLength(1);
242242
});
243+
244+
it('should support ref when exist status & text', () => {
245+
const badgeRef = React.createRef<HTMLSpanElement>();
246+
const { container } = render(<Badge ref={badgeRef} status="success" text="Success" />);
247+
expect(badgeRef.current).toBe(container.querySelector('.ant-badge'));
248+
});
243249
});

0 commit comments

Comments
 (0)