Skip to content

fix(input): correct classNames and styles TypeScript definitions#54162

Merged
afc163 merged 3 commits intoant-design:masterfrom
aojunhao123:fix-input-semantic-type
Jun 21, 2025
Merged

fix(input): correct classNames and styles TypeScript definitions#54162
afc163 merged 3 commits intoant-design:masterfrom
aojunhao123:fix-input-semantic-type

Conversation

@aojunhao123
Copy link
Copy Markdown
Contributor

🤔 This is a ...

  • 🤖 TypeScript definition improvement
  • 🐞 Bug fix

🔗 Related Issues

Fix Input component props type definition to align with documented API

💡 Background and Solution

📝 Change Log

Language Changelog
🇺🇸 English Input: Fix TypeScript definitions for classNames and styles props to match documented API
🇨🇳 Chinese Input: 修复 classNamesstyles 属性的 TypeScript 类型定义,与文档 API 保持一致

@bolt-new-by-stackblitz
Copy link
Copy Markdown

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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 21, 2025

📝 Walkthrough

Summary by CodeRabbit

  • 新功能

    • 输入组件现支持通过 classNamesstyles 属性为前缀、后缀、输入框和计数器等部分自定义样式和类名。
  • 样式

    • 优化了类名合并方式,提升了样式自定义的灵活性。

Walkthrough

本次变更为 Input 组件引入了 classNamesstyles 两个新属性,允许开发者通过语义化 key(如 prefix、suffix、input、count)自定义样式类和内联样式。同时,重命名了部分变量以提升代码可读性,并统一了 classnames 工具函数的命名。

Changes

文件/分组 变更摘要
components/input/Input.tsx 新增 classNamesstyles 属性,支持语义化样式覆盖;变量命名优化;统一 classnames 工具别名为 cls;相关逻辑调整以合并和传递自定义样式。

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant InputComponent
    participant RcInput

    User->>InputComponent: 传递 classNames/styles 属性
    InputComponent->>InputComponent: 合并 context 和 props 的 classNames/styles
    InputComponent->>RcInput: 传递合并后的 classNames/styles
    RcInput-->>InputComponent: 渲染带有自定义样式的输入框
Loading

Assessment against linked issues

Objective Addressed Explanation
修复 Input 组件未正确应用自定义 classNames 的问题 (#54149)
支持通过 props 传递并合并所有 classNames 到底层元素 (#54149)
允许开发者通过 props 对 Input 组件进行自定义样式覆盖 (#54149)

Assessment against linked issues: Out-of-scope changes

(未发现超出已关联 issue 目标的代码变更。)

Possibly related PRs

Suggested labels

lgtm

Suggested reviewers

  • li-jia-nan
  • afc163

Poem

兔子写代码,样式随心裁,
新增 classNames,风格任你来。
语义化的 key,定制更自在,
Input 组件焕新颜,
代码整洁又高端!

(_/)
( •_•)
/ >🌱


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f90fa36 and 731d1b6.

📒 Files selected for processing (1)
  • components/input/Input.tsx (6 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (16)
  • GitHub Check: test lib/es module (es, 1/2)
  • GitHub Check: test lib/es module (es, 2/2)
  • GitHub Check: build
  • GitHub Check: test-react-legacy (16, 1/2)
  • GitHub Check: test-react-legacy (16, 2/2)
  • GitHub Check: test-react-legacy (17, 2/2)
  • GitHub Check: test-react-latest (dom, 1/2)
  • GitHub Check: test-react-legacy (17, 1/2)
  • GitHub Check: test-react-latest (dom, 2/2)
  • GitHub Check: test-node
  • GitHub Check: lint
  • GitHub Check: build preview
  • GitHub Check: visual-diff snapshot (2/2)
  • GitHub Check: size
  • GitHub Check: visual-diff snapshot (1/2)
  • GitHub Check: build
🔇 Additional comments (8)
components/input/Input.tsx (8)

2-2: 良好的重命名以避免命名冲突。

将 classnames 工具函数的导入别名从 classNames 改为 cls,避免了与新增的 classNames 属性产生命名冲突,提升了代码可读性。


30-30: 语义化类型定义实现良好。

SemanticName 类型正确定义了 Input 组件的语义化区域键名,为开发者提供了类型安全的样式自定义方式。


48-49: TypeScript 接口定义正确且类型安全。

新增的 classNamesstyles 属性定义使用了正确的类型:

  • 使用 Partial<Record<...>> 允许开发者只定义需要的键
  • 基于 SemanticName 类型确保键名的类型安全
  • 属性为可选,保持向后兼容性

这些定义与文档 API 保持一致,解决了 TypeScript 类型定义问题。


71-71: 属性解构命名更加清晰。

将解构的属性名从 classes 重命名为 classNames,与接口定义保持一致,提升了代码的可读性和一致性。


178-185: 工具函数调用更新正确。

正确使用新的导入别名 cls 替代 classNames,保持了类名组合逻辑的完整性和正确性。


202-203: 语义化类名传递实现正确。

正确展开 classNames 属性,使得开发者可以通过语义化键名自定义组件各部分的类名,展开顺序确保了适当的优先级处理。


175-175: 样式属性传递实现正确。

正确合并上下文样式和组件样式,传递顺序确保了组件样式能够覆盖上下文样式,与类名处理方式保持一致。


204-243: 语义化类名实现规范且一致。

各个语义化区域的类名组合实现正确:

  • 正确使用 cls 函数和可选链式访问 classNames?.input
  • 保持了条件类名、上下文类名和哈希ID的组合逻辑
  • 实现模式在各个语义区域保持一致

注意:SemanticName 类型中定义的 'prefix'、'suffix'、'count' 键在此处未直接实现,可能由底层 RcInput 组件处理。

验证所有语义化键是否都被正确处理:

#!/bin/bash
# 描述:检查 RcInput 组件是否处理了所有 SemanticName 类型中定义的键
# 预期:找到 prefix、suffix、count 键的处理逻辑

echo "搜索 SemanticName 类型定义中的键在 RcInput 相关代码中的使用:"
rg -A 5 -B 5 "prefix.*suffix.*input.*count|count.*input.*suffix.*prefix" --type ts --type tsx
rg -A 3 "classNames.*prefix|classNames.*suffix|classNames.*count" --type ts --type tsx
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in 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
🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests 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.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 21, 2025

👁 Visual Regression Report for PR #54162 Passed ✅

🎯 Target branch: master (ddbf710)
📖 View Full Report ↗︎
📖 Alternative Report ↗︎

🎊 Congrats! No visual-regression diff found.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 21, 2025

Preview is ready

@coderabbitai coderabbitai Bot requested review from afc163 and li-jia-nan June 21, 2025 04:11
@coderabbitai coderabbitai Bot added the lgtm This PR has been approved by a maintainer label Jun 21, 2025
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Jun 21, 2025

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 21, 2025

Bundle Report

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

Detailed changes
Bundle name Size Change
antd.min-array-push 3.4MB -6.29MB (-64.95%) ⬇️

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) 1.85MB 1.85MB 100.0% 🚀
antd.min.js (New) 1.54MB 1.54MB 100.0% 🚀
antd-with-locales.js (Deleted) -5.1MB 0 bytes -100.0% 🗑️
antd.js (Deleted) -4.59MB 0 bytes -100.0% 🗑️

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (53e3a69) to head (3fc276a).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master    #54162   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          774       774           
  Lines        14032     14032           
  Branches      3713      3713           
=========================================
  Hits         14032     14032           

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

Comment thread components/input/Input.tsx
@afc163 afc163 merged commit 8f52938 into ant-design:master Jun 21, 2025
42 checks passed
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.

5 participants