Skip to content

Comments

feat(AutoComplete): support classNames and styles for component and ConfigProvider#53150

Merged
thinkasany merged 6 commits intonextfrom
cp-AutoComplete
Mar 20, 2025
Merged

feat(AutoComplete): support classNames and styles for component and ConfigProvider#53150
thinkasany merged 6 commits intonextfrom
cp-AutoComplete

Conversation

@thinkasany
Copy link
Member

@thinkasany thinkasany commented Mar 13, 2025

🤔 This is a ...

  • 🆕 New feature

📝 Change Log

Language Changelog
🇺🇸 English feat: ConfigProvider support classNames and styles for autoComplete
🇨🇳 Chinese feat: ConfigProvider support classNames and styles for autoComplete

Summary by CodeRabbit

  • 新功能

    • 增强 AutoComplete 组件样式定制能力,支持自定义类名和样式,提升组件灵活性。
    • 更新示例组件,提供多语言支持和交互式自动补全体验。
    • 调整 Select 组件下拉菜单位置,默认显示在组件左下方,优化界面布局。
  • 测试

    • 添加测试用例,确保 AutoComplete 组件在应用自定义类名和样式时表现正常。
  • 文档

    • 新增“Semantic DOM”部分,提供示例和交互说明,便于用户参考组件语义结构。

@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 Mar 13, 2025

👁 Visual Regression Report for PR #53150 Passed ✅

🎯 Target branch: next (2457cef)
📖 View Full Report ↗︎
📖 Alternative Report ↗︎

🎊 Congrats! No visual-regression diff found.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 13, 2025

Preview is ready

@petercat-assistant
Copy link

Walkthrough: This pull request introduces a new feature to the ConfigProvider component, allowing it to support classNames and styles for the AutoComplete component. This enhancement provides more flexibility in styling the AutoComplete component by allowing custom class names and styles to be applied to different semantic parts of the component.

Changes:

Files Changed Summary
components/auto-complete/AutoComplete.tsx Added support for classNames and styles properties in the AutoComplete component, allowing more granular styling. Deprecated popupClassName, dropdownClassName, dropdownStyle, and popupStyle in favor of the new properties.
components/auto-complete/tests/index.test.tsx Added tests to verify the support for classNames and styles in the AutoComplete component.
components/auto-complete/demo/_semantic.tsx Added a new demo file to showcase semantic DOM usage with the AutoComplete component.
components/auto-complete/demo/certain-category.tsx Updated demo to use the new classNames property instead of popupClassName.
components/auto-complete/index.en-US.md, components/auto-complete/index.zh-CN.md Updated documentation to include information about the new classNames and styles support for AutoComplete.
components/config-provider/context.ts Updated to include AutoCompleteConfig for classNames and styles.
components/config-provider/index.en-US.md, components/config-provider/index.zh-CN.md Updated documentation to reflect new autoComplete common props for ConfigProvider.


warning.deprecated(!('dataSource' in props), 'dataSource', 'options');
[
['dropdownClassName', 'classNames: {{ popup: ""}}'],

Choose a reason for hiding this comment

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

Ensure that mergedPopupStyle is correctly merged with contextStyles.popup and styles?.popup to avoid potential style conflicts or unintended overrides. Consider the order of merging to ensure the correct precedence of styles.

@thinkasany thinkasany mentioned this pull request Mar 13, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Mar 13, 2025

size-limit report 📦

Path Size
dist/antd.min.js 506.93 KB (+64 B 🔺)
dist/antd-with-locales.min.js 599.41 KB (+59 B 🔺)

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 13, 2025

Open in Stackblitz

More templates

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

commit: 1eb9fec

@codecov
Copy link

codecov bot commented Mar 13, 2025

Bundle Report

Changes will decrease total bundle size by 7.8MB (-66.65%) ⬇️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
antd.min-array-push 3.9MB -7.8MB (-66.65%) ⬇️

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 (New) 2.14MB 2.14MB 100.0% 🚀
antd.min.js (New) 1.76MB 1.76MB 100.0% 🚀
antd-with-locales.js (Deleted) -6.15MB 0 bytes -100.0% 🗑️
antd.js (Deleted) -5.55MB 0 bytes -100.0% 🗑️

Files in antd-with-locales.min.js:

  • ./components/config-provider/context.ts → Total Size: 1.51kB

Files in antd.min.js:

  • ./components/config-provider/context.ts → Total Size: 1.51kB

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Mar 13, 2025

Deploying ant-design with  Cloudflare Pages  Cloudflare Pages

Latest commit: 1eb9fec
Status: ✅  Deploy successful!
Preview URL: https://bbc3087f.ant-design.pages.dev
Branch Preview URL: https://cp-autocomplete.ant-design.pages.dev

View logs

@codecov
Copy link

codecov bot commented Mar 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (be8ec23) to head (1eb9fec).
Report is 3 commits behind head on next.

Additional details and impacted files
@@            Coverage Diff            @@
##              next    #53150   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          778       778           
  Lines        13995     13998    +3     
  Branches      3671      3670    -1     
=========================================
+ Hits         13995     13998    +3     

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

warning?: WarningContextProps;
alert?: AlertConfig;
affix?: ComponentStyleConfig;
autoComplete?: AutoCompleteConfig;
Copy link
Member

Choose a reason for hiding this comment

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

这个不要了吧,和 Select 共用就好。否则 theme.token 里不支持 AutoComplete 会比较奇怪。

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 19, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

这次变更主要调整了 AutoComplete 组件的样式处理方式。新增了 classNamesstyles 属性,用以替代原有的字符串方式,并对旧有的 popupClassNamedropdownClassNamepopupStyledropdownStyle 添加了过期提示。内部逻辑也相应更新以合并样式设置。同时,相关的测试用例、演示组件与文档均作了增强和补充;此外,还调整了部分其他组件的属性和导入顺序,以优化整体代码结构。

Changes

文件 变更摘要
components/auto-complete/AutoComplete.tsx 更新 AutoCompleteProps 接口,新增 classNamesstyles 属性,并对 popupClassNamedropdownClassNamepopupStyledropdownStyle 添加过期提示,合并样式逻辑。
components/auto-complete/__tests__/index.test.tsx 新增测试用例,验证 AutoComplete 组件自定义 classNames 与 styles 的使用。
components/auto-complete/demo/_semantic.tsx 新增展示组件 App 与 Block,提供 AutoComplete 语义化及本地化示例。
components/auto-complete/demo/certain-category.tsx 调整属性传递方式,将 popupClassName 改为基于 classNames 对象的结构化方式。
components/auto-complete/index.en-US.md
components/auto-complete/index.zh-CN.md
文档中新增 “Semantic DOM” 部分,添加代码片段引用,展示语义化示例。
components/config-provider/context.ts 调整 MasonryProps 的导入顺序,移除重复导入。
components/select/demo/_semantic.tsx 为 Select 组件新增 placement="bottomLeft" 属性,确定下拉菜单的位置。

Sequence Diagram(s)

sequenceDiagram
    participant U as 用户
    participant AC as AutoComplete 组件
    participant W as 警告检测器
    participant MS as 样式合并器
    U->>AC: 输入搜索文本
    AC->>W: 检查是否使用过期属性
    W-->>AC: 发出过期警告(如有)
    AC->>MS: 合并 popupStyle 与 dropdownStyle
    MS-->>AC: 返回合并样式
    AC-->>U: 渲染下拉菜单(自定义样式)
Loading

Poem

我是跳跃的兔子,编码路上不曾停步,
新添的样式如春风轻抚,
旧警告随风远去,留下灵动的新意味,
测试与示例齐声欢唱,代码花园灿烂开放,
🐰 蹦跶之间,创新就在眼前。
让我们向未来,一路跃进!


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@afc163
Copy link
Member

afc163 commented Mar 19, 2025

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 19, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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

🧹 Nitpick comments (3)
components/auto-complete/demo/_semantic.tsx (2)

1-68: 语义化演示示例实现得很好,但可以进一步优化类型定义

示例代码展示了 AutoComplete 组件的各个语义化部分,并且提供了多语言支持,实现得很好。不过 Block 组件的 props 类型使用了 any,可以更精确地定义类型。

建议将 Block 组件的参数类型进行如下优化:

- const Block = (prop: any) => {
+ const Block = (prop: Partial<AutoCompleteProps>) => {

这样可以获得更好的类型提示和检查,提高代码质量。


27-45: 建议优化 AutoComplete 组件的默认选项

当前 options 默认值只有一个选项 "thinkasany",这个选项与演示目的关联不大。考虑使用更有意义的默认选项来展示组件功能。

  const [options, setOptions] = React.useState<AutoCompleteProps['options']>([
-    { value: 'thinkasany' },
+    { value: 'example' },
+    { value: 'demo' },
+    { value: 'antd' },
  ]);
components/auto-complete/AutoComplete.tsx (1)

168-174: styles 合并逻辑良好,但 popup 样式可能需要注意优先级

样式合并逻辑基本合理,但 popup 样式合并时需要注意 zIndex 的优先级。当前实现中将计算得到的 zIndex 直接应用,这可能会覆盖用户在 styles.popup 中设置的值。

建议修改 popup 样式合并逻辑,确保用户提供的 zIndex 优先级更高:

- popup: { ...styles?.popup, ...mergedPopupStyle, zIndex },
+ popup: { ...styles?.popup, ...mergedPopupStyle, zIndex: styles?.popup?.zIndex ?? zIndex },
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 58daae6 and bce6589.

📒 Files selected for processing (8)
  • components/auto-complete/AutoComplete.tsx (5 hunks)
  • components/auto-complete/__tests__/index.test.tsx (1 hunks)
  • components/auto-complete/demo/_semantic.tsx (1 hunks)
  • components/auto-complete/demo/certain-category.tsx (1 hunks)
  • components/auto-complete/index.en-US.md (1 hunks)
  • components/auto-complete/index.zh-CN.md (1 hunks)
  • components/config-provider/context.ts (1 hunks)
  • components/select/demo/_semantic.tsx (1 hunks)
🧰 Additional context used
🧬 Code Definitions (2)
components/auto-complete/demo/_semantic.tsx (1)
components/auto-complete/AutoComplete.tsx (1) (1)
  • AutoCompleteProps (31-54)
components/auto-complete/AutoComplete.tsx (2)
components/config-provider/context.ts (2) (2)
  • ConfigConsumerProps (387-409)
  • ConfigContext (419-423)
components/config-provider/index.tsx (2) (2)
  • ConfigConsumerProps (114-114)
  • ConfigContext (111-111)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (13)
components/config-provider/context.ts (1)

28-28: 导入顺序调整,确保MasonryProps类型可用

类型导入位置调整,确保了MasonryProps类型能在文件中被正确引用。这是一个无功能性变更的代码整理。

components/select/demo/_semantic.tsx (1)

36-36: 添加了定位属性以控制下拉菜单位置

通过添加placement="bottomLeft"属性,明确指定了下拉菜单应该出现在Select组件的左下方,这增强了组件的可预测性和用户体验。

components/auto-complete/index.en-US.md (1)

86-88: 增加了语义DOM文档部分

新增了"Semantic DOM"文档部分,并引入了相关示例代码。这对于理解组件的DOM结构和实现更好的可访问性非常有价值。

components/auto-complete/demo/certain-category.tsx (1)

43-43: 更新为使用新的classNames API代替popupClassName

popupClassName属性替换为结构化的classNames={{ popup: 'certain-category-search-dropdown' }},符合组件API的最新变更。这种方式提供了更灵活和一致的样式管理方法。

components/auto-complete/index.zh-CN.md (1)

87-89: 文档增加了语义化 DOM 部分,很好!

增加了"语义化 DOM"章节并引用了新的示例代码,这对用户理解组件结构很有帮助。

components/auto-complete/__tests__/index.test.tsx (1)

100-141: 测试用例完善,覆盖了新增的 classNames 和 styles 特性

这个测试用例很全面地验证了 AutoComplete 组件对新增的 classNames 和 styles 属性的支持,包括对根元素、输入框、列表、列表项和弹出层的样式定制能力。测试结构清晰,断言完备。

components/auto-complete/AutoComplete.tsx (7)

21-21: 新增 SemanticName 类型定义很好地支持了语义化样式

定义 SemanticName 类型明确了组件的语义化结构,有助于开发者理解可定制的部分,符合组件的整体设计理念。


41-48: 弃用提示更新清晰明确

为 popupClassName、dropdownClassName、popupStyle 和 dropdownStyle 添加了明确的弃用提示,并提供了替代方案,有助于用户平滑迁移到新的 API。


52-53: 新增 classNames 和 styles 属性提供了更灵活的样式定制能力

添加这两个属性使 AutoComplete 组件的样式定制能力与其他组件保持一致,增强了整体 API 的一致性。这种结构化的方式比单独的样式属性更加清晰。


130-138: 重构警告代码结构清晰,易于维护

使用数组存储废弃属性和替代方案,然后循环处理,代码更简洁、更易于维护。这种方式也便于将来添加新的废弃属性。


150-153: 合并弹出层样式并处理 zIndex

正确合并了 popupStyle 和 dropdownStyle,并且适当处理了 zIndex。这确保了样式的正确应用和层级管理。

请确保在合并样式时不会有意外覆盖,特别是当 ConfigProvider 中也提供了样式时。建议检查样式合并的优先级是否符合预期。


155-166: classNames 合并逻辑清晰完整

合并类名的逻辑考虑了默认类名、用户自定义类名和废弃属性,保证了向后兼容性。特别是 popup 类名合并了 popupClassName 和 dropdownClassName,确保了平滑过渡。


182-183: 将合并后的样式和类名传递给 Select 组件

正确地将处理后的 classNames 和 styles 传递给了底层的 Select 组件,确保样式能正确应用。

/** @deprecated Please use `classNames: {{ popup: ""}}` instead */
dropdownClassName?: string;
/** @deprecated Please use `styles: {{ popup: {}}}` instead */
dropdownStyle?: React.CSSProperties;
Copy link
Member

Choose a reason for hiding this comment

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

dropdownStylepopupStyle 在 v5 里本来就没有,不需要加了再 deprecated

Copy link
Member Author

Choose a reason for hiding this comment

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

dropdownStyle 好像还在的。 popupStyle确实没必要了
image

import SemanticPreview from '../../../.dumi/components/SemanticPreview';
import useLocale from '../../../.dumi/hooks/useLocale';

const locales = {
Copy link
Member

Choose a reason for hiding this comment

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

zIndex:

截屏2025-03-19 19 13 57

warning.deprecated(!('dataSource' in props), 'dataSource', 'options');
[
['dropdownClassName', 'classNames.popup'],
['popupClassName', 'classNames.popup}'],
Copy link
Member

Choose a reason for hiding this comment

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

多了个 }

Copy link
Member

Choose a reason for hiding this comment

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

warning 缺了对应的测试用例

Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
Signed-off-by: thinkasany <[email protected]>
@thinkasany thinkasany merged commit 666cebb into next Mar 20, 2025
44 checks passed
@thinkasany thinkasany deleted the cp-AutoComplete branch March 20, 2025 03:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants