Skip to content

Comments

feat(CheckableTagGroup): Support better customization with semantic classNames/styles as function#55796

Merged
meet-student merged 1 commit intoant-design:masterfrom
meet-student:tag-group
Nov 21, 2025
Merged

feat(CheckableTagGroup): Support better customization with semantic classNames/styles as function#55796
meet-student merged 1 commit intoant-design:masterfrom
meet-student:tag-group

Conversation

@meet-student
Copy link
Member

中文版模板 / 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 Support better customization with semantic classNames/styles as function
🇨🇳 Chinese Support better customization with semantic classNames/styles as function

@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 Nov 21, 2025

Preview is ready

@github-actions
Copy link
Contributor

github-actions bot commented Nov 21, 2025

Visual Regression Build for PR #55796 Failed ❌

Potential causes:

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @meet-student, 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 significantly improves the customization capabilities of the CheckableTagGroup component. By allowing classNames and styles to be defined as functions, it empowers developers to implement more sophisticated and responsive designs that adapt to the component's state or specific use cases. This change enhances the component's utility and aligns with modern React development patterns for flexible styling.

Highlights

  • Enhanced Customization for CheckableTagGroup: The CheckableTagGroup component now supports classNames and styles props as functions, allowing for dynamic and context-aware styling based on the component's properties. This provides greater flexibility for developers to customize the appearance of the tag group and its individual items.
  • Integration of useMergeSemantic Hook: A new useMergeSemantic hook has been introduced and integrated into CheckableTagGroup.tsx. This hook efficiently merges semantic class names and styles provided through component props and context, ensuring a consistent and extensible styling mechanism.
  • Updated Documentation and Demos: The documentation for Tag.CheckableTagGroup (both English and Chinese) has been updated to reflect the new functional classNames and styles capabilities. Corresponding demo files and snapshot tests have also been adjusted to showcase and validate these new customization options.
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.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 21, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

📝 Walkthrough

Summary by CodeRabbit

发布说明

  • 新功能

    • CheckableTagGroup 组件样式自定义现支持对象和函数两种形式
    • CheckableTagGroup 组件添加 onChange 事件回调
  • 文档

    • 完善 Tag 组件 API 文档和语义结构说明
    • 新增 CheckableTagGroup 样式自定义演示代码

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

总体概述

CheckableTagGroup 组件进行了重构:替换为 SemanticClassNamesType / SemanticStylesType,增加 CheckableTagGroupBaseProps,导出 CheckableTagGroupClassNamesTypeCheckableTagGroupStylesType,并使用 useMergeSemantic 从上下文与本地 props 合并语义化 classNames/styles,渲染时同时应用 contextClassName/contextStyle 与已合并样式。

Walkthrough

该变更重构了 CheckableTagGroup 的语义样式/类名类型与合并流程,引入 useMergeSemantic,更新相关测试、文档与示例以支持对象与函数形式的 classNames/styles。

Changes

Cohort / File(s) 变更摘要
组件核心逻辑
components/tag/CheckableTagGroup.tsx
SemanticClassNamesType / SemanticStylesType 替换旧类型;新增 CheckableTagGroupBaseProps;导出 CheckableTagGroupClassNamesTypeCheckableTagGroupStylesType;引入并使用 useMergeSemantic 合并 context 与本地的 classNames/styles;渲染时应用 contextClassName / contextStyle
测试套件
components/tag/__tests__/semantic.test.tsx
用对象/函数两种形式的 classNames/styles 扩展并替换语义测试,增加针对 Tag 与 CheckableTagGroup(包括多选/禁用等状态)的类名与内联样式断言。
示例代码
components/tag/demo/style-class.tsx
新增 Space 导入与 CheckableTagGroupProps 类型别名;添加 groupStylesgroupStylesFn(静态/动态样式示例);布局中增加两个 CheckableTagGroup 示例以展示对象和函数样式用法。
文档(英文/中文)
components/tag/index.en-US.md
components/tag/index.zh-CN.md
统一 API 表头为 Property/Description/Type/Default/Version;更新 classNamesstyles 描述为“支持对象或函数”;为 Tag.CheckableTagGroup 添加 semantic-group 锚点;在表格中新增/调整 stylesonChangevalue 等项的说明与类型签名。

Sequence Diagram(s)

sequenceDiagram
    participant Dev as Developer Code (props)
    participant Ctx as Component Config Context
    participant Merge as useMergeSemantic
    participant Comp as CheckableTagGroup (render)

    Dev->>Comp: render with props (classNames/styles, ...)
    Ctx->>Merge: provide contextClassNames/contextStyles + contextClassName/contextStyle
    Dev->>Merge: provide local classNames/styles
    Merge-->>Comp: mergedClassNames & mergedStyles
    Note right of Comp#ffffff: Comp applies merged\nclassNames/styles to root and items
    Comp->>Comp: render children with preserved item styles
Loading

Estimated code review effort

🎯 3 (中等) | ⏱️ ~30 分钟

需要重点审查:

  • components/tag/CheckableTagGroup.tsx:类型变化(SemanticClassNamesType/SemanticStylesType)、useMergeSemantic 的集成与上下文 class/style 的合并与应用点;
  • components/tag/__tests__/semantic.test.tsx:新增/修改的断言是否覆盖对象与函数两种语义形式及状态分支(多选、禁用等);
  • 文档与示例:中英文描述是否一致且与新类型签名匹配。

"Poem" by a rabbit follows below.

我是小兔写代码,跳跃在语义间,
合并样式与类名,轻轻握住新版颜,
文档与测试同欢笑,示例里花开满版,
鼓掌一跳又一跳,新变更,轻盈又欢。 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed 标题准确概括了这个PR的核心变化:为CheckableTagGroup添加了支持函数形式的语义化classNames/styles定制功能。
Description check ✅ Passed 描述通过变更日志清晰地说明了功能增强内容,与代码变更相关。尽管缺少详细的背景和方案说明,但仍与变更集相关。
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 adds a valuable feature to CheckableTagGroup, allowing classNames and styles to be passed as functions for more dynamic and powerful customization. The implementation is solid, correctly leveraging the useMergeSemantic hook and updating types, tests, and documentation accordingly. The changes align CheckableTagGroup with the customization patterns of other components in the library. I have one suggestion to improve the robustness of the new tests.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 21, 2025

More templates

npm i https://pkg.pr.new/ant-design/ant-design/antd@55796

commit: 842c499

zombieJ
zombieJ previously approved these changes Nov 21, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Nov 21, 2025
@codecov
Copy link

codecov bot commented Nov 21, 2025

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff            @@
##            master    #55796   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          803       803           
  Lines        14805     14804    -1     
  Branches      3915      3913    -2     
=========================================
- Hits         14805     14804    -1     

☔ 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.

@codecov
Copy link

codecov bot commented Nov 21, 2025

Bundle Report

Changes will decrease total bundle size by 1.57kB (-0.04%) ⬇️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
antd.min-array-push 3.91MB -1.57kB (-0.04%) ⬇️

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 -786 bytes 2.15MB -0.04%
antd.min.js -786 bytes 1.76MB -0.04%

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
components/tag/__tests__/semantic.test.tsx (1)

158-173: 建议对根元素也使用 toHaveStyle 匹配器。

根元素样式断言仍使用 getAttribute('style')toContain,这与之前的审查建议相同。为保持一致性和健壮性,建议对根元素也使用 toHaveStyle 匹配器。

-    expect(groupElement).toHaveClass('multiple-group');
-    expect(groupElement).toHaveAttribute('style');
-    const rootStyle = groupElement?.getAttribute('style');
-    expect(rootStyle).toContain('padding: 8px');
-    expect(rootStyle).toContain('background-color: transparent');
+    expect(groupElement).toHaveClass('multiple-group');
+    expect(groupElement).toHaveStyle({
+      padding: '8px',
+      backgroundColor: 'transparent',
+    });
🧹 Nitpick comments (2)
components/tag/__tests__/semantic.test.tsx (2)

40-55: 建议使用 toHaveStyle 匹配器。

当前使用 getAttribute('style')toContain 检查样式较为脆弱,容易受样式顺序或空格变化影响。建议使用 @testing-library/jest-domtoHaveStyle 匹配器,使测试更清晰且更健壮。

-    expect(tagElement).toHaveAttribute('style');
-    const rootStyle = tagElement?.getAttribute('style');
-    expect(rootStyle).toContain('background-color: lightblue');
-    expect(rootStyle).toContain('border: 2px solid blue');
+    expect(tagElement).toHaveStyle({
+      backgroundColor: 'lightblue',
+      border: '2px solid blue',
+    });

-    expect(iconElement).toHaveAttribute('style');
-    const iconStyle = iconElement?.getAttribute('style');
-    expect(iconStyle).toContain('color: red');
-    expect(iconStyle).toContain('font-size: 16px');
+    expect(iconElement).toHaveStyle({
+      color: 'red',
+      fontSize: '16px',
+    });

-    expect(contentElement).toHaveClass('custom-tag-content');
-    expect(contentElement).toHaveAttribute('style');
-    const contentStyle = contentElement?.getAttribute('style');
-    expect(contentStyle).toContain('background-color: yellow');
-    expect(contentStyle).toContain('color: green');
+    expect(contentElement).toHaveClass('custom-tag-content');
+    expect(contentElement).toHaveStyle({
+      backgroundColor: 'yellow',
+      color: 'green',
+    });

93-107: 同样建议使用 toHaveStyle 匹配器。

与前一个测试相同,建议改用 toHaveStyle 匹配器以提高测试的健壮性和可读性。

-    expect(tagElement).toHaveAttribute('style');
-    const rootStyle = tagElement?.getAttribute('style');
-    expect(rootStyle).toContain('background-color: lightblue');
-    expect(rootStyle).toContain('border-radius: 8px');
+    expect(tagElement).toHaveStyle({
+      backgroundColor: 'lightblue',
+      borderRadius: '8px',
+    });

-    expect(iconElement).toHaveAttribute('style');
-    const iconStyle = iconElement?.getAttribute('style');
-    expect(iconStyle).toContain('color: blue');
-    expect(iconStyle).toContain('font-size: 18px');
+    expect(iconElement).toHaveStyle({
+      color: 'blue',
+      fontSize: '18px',
+    });

-    expect(contentElement).toHaveClass('content-enabled');
-    expect(contentElement).toHaveAttribute('style');
-    const contentStyle = contentElement?.getAttribute('style');
-    expect(contentStyle).toContain('font-weight: bold');
-    expect(contentStyle).toContain('color: darkblue');
+    expect(contentElement).toHaveClass('content-enabled');
+    expect(contentElement).toHaveStyle({
+      fontWeight: 'bold',
+      color: 'darkblue',
+    });
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4d8013e and 842c499.

⛔ Files ignored due to path filters (2)
  • components/tag/__tests__/__snapshots__/demo-extend.test.ts.snap is excluded by !**/*.snap
  • components/tag/__tests__/__snapshots__/demo.test.tsx.snap is excluded by !**/*.snap
📒 Files selected for processing (5)
  • components/tag/CheckableTagGroup.tsx (6 hunks)
  • components/tag/__tests__/semantic.test.tsx (2 hunks)
  • components/tag/demo/style-class.tsx (2 hunks)
  • components/tag/index.en-US.md (3 hunks)
  • components/tag/index.zh-CN.md (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • components/tag/index.en-US.md
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-11-13T02:52:08.942Z
Learnt from: meet-student
Repo: ant-design/ant-design PR: 55697
File: components/drawer/index.tsx:86-88
Timestamp: 2025-11-13T02:52:08.942Z
Learning: In Ant Design components (components/**/*.{ts,tsx}), always use `import useId from 'rc-util/lib/hooks/useId'` instead of `React.useId()` for generating unique IDs, to ensure compatibility with React 16-19. The rc-util hook automatically uses the native implementation in React 18+ and provides a fallback for older versions.

Applied to files:

  • components/tag/CheckableTagGroup.tsx
🧬 Code graph analysis (2)
components/tag/CheckableTagGroup.tsx (2)
components/_util/hooks/useMergeSemantic.ts (3)
  • SemanticClassNamesType (16-20)
  • SemanticStylesType (22-26)
  • useMergeSemantic (118-152)
components/config-provider/context.ts (1)
  • useComponentConfig (561-575)
components/tag/demo/style-class.tsx (3)
components/tag/CheckableTagGroup.tsx (1)
  • CheckableTagGroupProps (59-63)
components/tag/index.tsx (1)
  • CheckableTagGroupProps (23-23)
components/index.ts (1)
  • GetProps (5-5)
⏰ 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). (14)
  • GitHub Check: build
  • GitHub Check: visual-diff snapshot (1/2)
  • GitHub Check: visual-diff snapshot (2/2)
  • GitHub Check: test lib/es module (es, 2/2)
  • GitHub Check: test lib/es module (es, 1/2)
  • GitHub Check: test-react-latest (dom, 2/2)
  • GitHub Check: test-node
  • GitHub Check: test-react-latest (dom, 1/2)
  • GitHub Check: build
  • GitHub Check: test-react-legacy (18, 2/2)
  • GitHub Check: lint
  • GitHub Check: test-react-legacy (18, 1/2)
  • GitHub Check: build preview
  • GitHub Check: size
🔇 Additional comments (13)
components/tag/CheckableTagGroup.tsx (5)

7-8: 导入正确。

新增的语义类型和 hook 导入正确,与工具库匹配。


35-63: 类型重构良好。

将基础 props 抽取为 CheckableTagGroupBaseProps,并导出语义类型 CheckableTagGroupClassNamesTypeCheckableTagGroupStylesType,支持对象和函数形式的 classNames/styles 定制。类型定义正确且可组合。


93-100: 正确提取上下文配置。

useComponentConfig 提取 contextClassNamecontextStylecontextClassNamescontextStyles,使组件能够合并全局配置和局部 props。


108-115: 语义合并实现正确。

使用 useMergeSemantic 正确合并上下文和局部的 classNames/styles,优先级顺序合理(上下文在前,局部在后)。


168-185: 渲染逻辑正确应用语义样式。

正确将 contextClassName/contextStyle 和合并后的语义 classNames/styles 应用到根元素,优先级顺序合理。

components/tag/index.zh-CN.md (3)

42-42: Tag API 文档更新准确。

classNames 和 styles 的描述正确说明支持对象或函数形式,类型签名完整。

Also applies to: 49-49


65-65: CheckableTagGroup API 文档更新完整。

classNames/styles 描述正确引用 semantic-group 锚点,类型签名准确展示对象和函数两种形式。

Also applies to: 70-71


80-80: 语义分组锚点添加正确。

添加 {#semantic-group} 锚点使 API 表格能够正确链接到 CheckableTagGroup 的语义 DOM 结构说明。

components/tag/demo/style-class.tsx (4)

3-7: 导入和类型定义正确。

正确导入 Space 用于布局,使用 GetProps 提取 CheckableTagGroupProps 类型用于样式定义。


44-56: 对象形式样式定义正确。

groupStyles 定义了 root 和 item 的静态样式,类型正确且符合语义结构。


58-77: 函数形式样式定义正确。

groupStylesFn 根据 multiple prop 动态返回样式,演示了函数形式的灵活性。使用 satisfies 确保类型安全。


83-110: 演示 UI 更新合理。

新增两个 Tag.CheckableTagGroup 实例分别演示对象和函数形式的 styles,布局清晰,功能展示完整。

components/tag/__tests__/semantic.test.tsx (1)

109-133: CheckableTagGroup 对象测试正确。

正确使用 toHaveStyle 匹配器验证样式,测试结构清晰且健壮。

@meet-student meet-student merged commit d5bcfab into ant-design:master Nov 21, 2025
38 of 39 checks passed
@meet-student meet-student deleted the tag-group branch November 21, 2025 10:09
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.

3 participants