Skip to content

fix: Badge ref not working with text mode#56532

Merged
meet-student merged 1 commit intomasterfrom
fix-badge-ref
Jan 8, 2026
Merged

fix: Badge ref not working with text mode#56532
meet-student merged 1 commit intomasterfrom
fix-badge-ref

Conversation

@zombieJ
Copy link
Member

@zombieJ zombieJ commented Jan 8, 2026

中文版模板 / Chinese template

🤔 This is a ...

  • 🆕 New feature
  • 🐞 Bug fix
  • 📝 Site / documentation improvement
  • 📽️ Demo improvement
  • 💄 Component style improvement
  • 🤖 TypeScript definition improvement
  • 📦 Bundle size optimization
  • ⚡️ Performance optimization
  • ⭐️ Feature enhancement
  • 🌐 Internationalization
  • 🛠 Refactoring
  • 🎨 Code style optimization
  • ✅ Test Case
  • 🔀 Branch merge
  • ⏩ Workflow
  • ⌨️ Accessibility improvement
  • ❓ Other (about what?)

🔗 Related Issues

  • Describe the source of related requirements, such as links to relevant issue discussions.
  • For example: close #xxxx, fix #xxxx

💡 Background and Solution

  • The specific problem to be addressed.
  • List the final API implementation and usage if needed.
  • If there are UI/interaction changes, consider providing screenshots or GIFs.

📝 Change Log

Language Changelog
🇺🇸 English Fix Badge ref not working with text props.
🇨🇳 Chinese 修复 Badge 在使用 text 属性时,ref 无效的问题。

@bolt-new-by-stackblitz
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 8, 2026

Preview is ready

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @zombieJ, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a bug in the Badge component where the ref prop was not being correctly applied when the component was used in text mode. The fix ensures that the ref is properly forwarded to the component's root DOM element, allowing for direct manipulation or access. A corresponding test case has been added to validate this behavior, improving the component's reliability and developer experience.

Highlights

  • Badge Component Ref Forwarding: Corrected an issue where the ref prop was not properly forwarded to the root <span> element of the Badge component when used with the text prop. This ensures that developers can correctly access the underlying DOM element.
  • Test Coverage: Added a new test case to index.test.tsx to specifically verify that the ref prop functions as expected when the Badge component is rendered with both status and text props.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 8, 2026

👁 Visual Regression Report for PR #56532 Failed ❌

🎯 Target branch: master (6c5036e)
📖 View Full Report ↗︎
📖 Alternative Report ↗︎
📊 Summary: 🔄 3 changed

Expected (Branch master) Actual (Current PR) Diff
list-vertical.dark.png list-vertical.dark.png list-vertical.dark.png list-vertical.dark.png
table-sticky.dark.png table-sticky.dark.png table-sticky.dark.png table-sticky.dark.png
table-sticky.default.png table-sticky.default.png table-sticky.default.png table-sticky.default.png

Important

There are 3 diffs found in this PR: 🔄 3 changed.
Please check all items:

  • Visual diff is acceptable

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 8, 2026

📝 Walkthrough

Summary by CodeRabbit

发布说明

  • 缺陷修复

    • 改进了徽章组件在特定场景下的引用转发,确保行为一致性。
  • 测试

    • 添加了对徽章组件引用转发功能的测试覆盖,提高代码质量。

✏️ Tip: You can customize this high-level summary in your review settings.

功能概述

Badge组件在status-only渲染分支中添加了ref转发支持,并新增测试用例验证该功能。总改动量:7行。

改动清单

文件组 / 文件 改动说明
Badge 组件ref转发修复
components/badge/Badge.tsx
在没有children但存在status的渲染路径中,外层span元素添加 ref={ref} 转发React ref,确保ref转发行为的一致性
ref转发验证测试
components/badge/__tests__/index.test.tsx
新增测试用例,验证Badge组件在同时提供status和text属性时能够正确转发ref到HTMLSpanElement

预期代码审查工作量

🎯 1 (Trivial) | ⏱️ ~3 分钟

庆祝诗

🐰 徽章又添新魔法,
Ref 转发更齐全,
细微修缮皆完美,
测试覆盖保周全!
小兔为此欢呼雀跃 🎉

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed 标题清晰准确地总结了主要变更:修复了Badge组件在使用text模式时ref不工作的问题。
Description check ✅ Passed 描述内容与变更集相关,包括了问题说明和两种语言的更新日志,明确指出了修复的是Badge组件在使用text属性时ref无效的问题。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-badge-ref

📜 Recent review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6c5036e and c2bbb45.

📒 Files selected for processing (2)
  • components/badge/Badge.tsx
  • components/badge/__tests__/index.test.tsx
🧰 Additional context used
📓 Path-based instructions (8)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.{ts,tsx}: Always use TypeScript with strict type checking
Never use any type - define precise types instead
Use interfaces (not type aliases) for object structures
Export all public interface types
Prefer union types over enums, use as const for constants
Use early returns to improve readability
Support tree shaking
Follow import order: React → dependencies → antd components → custom components → types → styles
Prefer antd built-in components over external dependencies
Pass all ESLint and TypeScript checks
No console errors or warnings

**/*.{ts,tsx}: Use TypeScript and React to develop, with function-based components and hooks instead of class components
Use early returns to improve code readability
Component names should use PascalCase
Property names should use camelCase
Use React.memo, useMemo, and useCallback appropriately to optimize performance
All components and functions must provide accurate type definitions; avoid using any type and use interfaces instead of type aliases for object structures
Component props should use interface definition with naming convention ComponentNameProps; define separate interfaces for component state like ComponentNameState
Use React.ForwardRefRenderFunction for component ref types and explicitly define all callback function parameters and return values
Use generics appropriately to enhance type flexibility; use union types and as const instead of enum; rely on TypeScript's type inference and minimize type assertions
Internationalization: obtain locale configuration via useLocale hook from components/locale/index.tsx; ensure new locale configurations have corresponding type definitions

Files:

  • components/badge/__tests__/index.test.tsx
  • components/badge/Badge.tsx
components/**/*.tsx

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

components/**/*.tsx: Component props interfaces should be named ComponentNameProps
Component ref types should use React.ForwardRefRenderFunction
Use functional components with hooks exclusively (no class components)
Apply performance optimizations with React.memo, useMemo, useCallback appropriately
Support server-side rendering
Components must support ref forwarding with structure including nativeElement, focus, and other methods
Use PascalCase for component names
Use camelCase for props with specific patterns: default + PropName for defaults, forceRender for force rendering, open instead of visible for panel state, show + PropName for display toggles, PropName + able for capabilities, dataSource for data source, disabled for disabled state, extra for additional content, icon for icons, trigger for triggers, className for CSS classes
Use on + EventName pattern for event handlers (e.g., onClick, onChange)
Use on + SubComponentName + EventName pattern for sub-component events
Use complete names, never abbreviations in prop naming
Optimize for minimal re-renders
Use useLocale hook from components/locale/index.tsx
Support accessibility (WCAG 2.1 AA)

Files:

  • components/badge/__tests__/index.test.tsx
  • components/badge/Badge.tsx
components/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Never hardcode colors, sizes, or spacing values

Files:

  • components/badge/__tests__/index.test.tsx
  • components/badge/Badge.tsx
**/__tests__/**/*.test.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/__tests__/**/*.test.{ts,tsx}: Write comprehensive tests using Jest and React Testing Library
Include snapshot tests for UI components

Files:

  • components/badge/__tests__/index.test.tsx
**/*.{ts,tsx,md}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Use 2-space indentation

Files:

  • components/badge/__tests__/index.test.tsx
  • components/badge/Badge.tsx
**/*.{ts,tsx,css}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Maintain cross-browser compatibility

Files:

  • components/badge/__tests__/index.test.tsx
  • components/badge/Badge.tsx
**/*.tsx

📄 CodeRabbit inference engine (AGENTS.md)

**/*.tsx: Use @ant-design/cssinjs as the styling solution; place component styles in style/ directory with filenames following gen[ComponentName]Style naming convention
Use CSS-in-JS and avoid hardcoded colors, sizes, and spacing values; base component styles on global and component-level design tokens
Components must support dark mode, different screen sizes, and RTL (right-to-left) reading direction; use CSS logical properties like margin-inline-start instead of directional properties
Use CSS transitions for simple animations and @rc-component/motion for complex animations; respect prefers-reduced-motion user preference
Follow WCAG 2.1 AA accessibility standards: ensure clear focus states, sufficient color contrast, avoid color-only information conveyance, support 200% page zoom, and avoid flickering animations

Files:

  • components/badge/__tests__/index.test.tsx
  • components/badge/Badge.tsx
**/*.test.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Use Jest and React Testing Library for unit tests; place test files in tests directory with naming format index.test.tsx or xxx.test.tsx; achieve 100% test coverage

Files:

  • components/badge/__tests__/index.test.tsx
🧠 Learnings (6)
📓 Common learnings
Learnt from: CR
Repo: ant-design/ant-design PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-04T15:16:45.886Z
Learning: Applies to CHANGELOG.*.md : CHANGELOG format: `Component: 📌emoji Description [#PR](link) [contributor]`; use code backticks for all property names, method names, APIs, and aria/role attributes; maintain space between Chinese/English and numbers/links/usernames
📚 Learning: 2025-11-24T16:30:28.374Z
Learnt from: CR
Repo: ant-design/ant-design PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-24T16:30:28.374Z
Learning: Applies to components/**/*.tsx : Components must support ref forwarding with structure including nativeElement, focus, and other methods

Applied to files:

  • components/badge/__tests__/index.test.tsx
  • components/badge/Badge.tsx
📚 Learning: 2025-11-24T16:30:28.374Z
Learnt from: CR
Repo: ant-design/ant-design PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-24T16:30:28.374Z
Learning: Applies to components/**/*.tsx : Component ref types should use `React.ForwardRefRenderFunction`

Applied to files:

  • components/badge/__tests__/index.test.tsx
  • components/badge/Badge.tsx
📚 Learning: 2025-11-24T16:30:28.374Z
Learnt from: CR
Repo: ant-design/ant-design PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-24T16:30:28.374Z
Learning: Applies to components/**/*.tsx : Support accessibility (WCAG 2.1 AA)

Applied to files:

  • components/badge/__tests__/index.test.tsx
📚 Learning: 2026-01-04T15:16:45.886Z
Learnt from: CR
Repo: ant-design/ant-design PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-04T15:16:45.886Z
Learning: Applies to **/*.{ts,tsx} : Use `React.ForwardRefRenderFunction` for component ref types and explicitly define all callback function parameters and return values

Applied to files:

  • components/badge/Badge.tsx
📚 Learning: 2025-11-24T16:30:28.374Z
Learnt from: CR
Repo: ant-design/ant-design PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-24T16:30:28.374Z
Learning: Applies to components/**/*.tsx : Optimize for minimal re-renders

Applied to files:

  • components/badge/Badge.tsx
🧬 Code graph analysis (1)
components/badge/__tests__/index.test.tsx (1)
tests/__mocks__/rc-util/lib/Portal.tsx (1)
  • render (23-29)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (18)
  • GitHub Check: build preview
  • GitHub Check: test lib/es module (es, 2/2)
  • GitHub Check: lint
  • GitHub Check: test-react-legacy (18, 2/2)
  • GitHub Check: build
  • GitHub Check: test-react-latest (dom, 2/2)
  • GitHub Check: test-node
  • GitHub Check: test lib/es module (lib, 1/2)
  • GitHub Check: test lib/es module (es, 1/2)
  • GitHub Check: test lib/es module (lib, 2/2)
  • GitHub Check: test-react-latest (dom, 1/2)
  • GitHub Check: test-react-legacy (18, 1/2)
  • GitHub Check: visual-diff snapshot (1/2)
  • GitHub Check: visual-diff snapshot (2/2)
  • GitHub Check: build
  • GitHub Check: size
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Cloudflare Pages: ant-design-next
🔇 Additional comments (2)
components/badge/__tests__/index.test.tsx (1)

244-248: 测试用例实现正确!

新增的测试用例有效验证了当同时存在 statustext 属性时,ref 转发功能是否正常工作。测试逻辑清晰,类型注解准确,完美覆盖了 PR 要修复的场景。

components/badge/Badge.tsx (1)

214-214: 修复正确且必要!

在状态模式的渲染分支中添加 ref={ref} 确保了 ref 转发的一致性。此修改与主返回路径(第 230 行)的实现保持一致,成功修复了当使用 text 属性时 ref 无法正常工作的问题。改动最小化且无副作用。


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly fixes a bug where the ref was not being forwarded on a Badge component when used in text mode without children. The fix involves adding the ref to the appropriate <span> element in the status-only rendering path. A new test case has also been added to verify this fix and prevent future regressions. The changes are correct and well-tested.

@cloudflare-workers-and-pages
Copy link

Deploying ant-design-next with  Cloudflare Pages  Cloudflare Pages

Latest commit: c2bbb45
Status: ✅  Deploy successful!
Preview URL: https://deeb1acb.ant-design-next.pages.dev
Branch Preview URL: https://fix-badge-ref.ant-design-next.pages.dev

View logs

@github-actions
Copy link
Contributor

github-actions bot commented Jan 8, 2026

size-limit report 📦

Path Size
dist/antd.min.js 522.94 KB (-2 B 🔽)
dist/antd-with-locales.min.js 616.79 KB (-2 B 🔽)

@cloudflare-workers-and-pages
Copy link

Deploying ant-design with  Cloudflare Pages  Cloudflare Pages

Latest commit: c2bbb45
Status: ✅  Deploy successful!
Preview URL: https://0ed07f47.ant-design.pages.dev
Branch Preview URL: https://fix-badge-ref.ant-design.pages.dev

View logs

@meet-student
Copy link
Member

这个没相关 issue 吗

@codecov
Copy link

codecov bot commented Jan 8, 2026

Bundle Report

Changes will increase total bundle size by 12 bytes (0.0%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
antd.min-array-push 3.86MB 12 bytes (0.0%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: antd.min-array-push

Assets Changed:

Asset Name Size Change Total Size Change (%)
antd-with-locales.min.js 6 bytes 2.12MB 0.0%
antd.min.js 6 bytes 1.74MB 0.0%

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 8, 2026

@codecov
Copy link

codecov bot commented Jan 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (6c5036e) to head (c2bbb45).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master    #56532   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          805       805           
  Lines        14847     14847           
  Branches      3920      3920           
=========================================
  Hits         14847     14847           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@zombieJ
Copy link
Member Author

zombieJ commented Jan 8, 2026

这个没相关 issue 吗

没有,业务发现的

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jan 8, 2026
@meet-student meet-student merged commit ee8cc27 into master Jan 8, 2026
50 checks passed
@meet-student meet-student deleted the fix-badge-ref branch January 8, 2026 07:05
@zombieJ zombieJ mentioned this pull request Jan 13, 2026
17 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants