feat(Input): support semantic DOM#53958
Conversation
|
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the 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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
👁 Visual Regression Report for PR #53958 Passed ✅
🎊 Congrats! No visual-regression diff found.
|
WalkthroughThis pull request introduces semantic DOM support for input components in the Ant Design library. It adds the ability to customize class names and styles for various input elements, enhancing the flexibility and accessibility of the components. The changes include updates to the input, search, password, OTP, and textarea components, along with corresponding tests and documentation updates. Changes
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## next #53958 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 788 788
Lines 14334 14343 +9
Branches 3787 3788 +1
=========================================
+ Hits 14334 14343 +9 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Bundle ReportChanges will increase total bundle size by 1.29kB (0.03%) ⬆️. This is within the configured threshold ✅ Detailed changes
Affected Assets, Files, and Routes:view changes for bundle: antd.min-array-pushAssets Changed:
Files in
Files in
|
More templates
commit: |
components/input/__tests__/__snapshots__/demo-extend.test.ts.snap
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull Request Overview
This PR adds semantic DOM support by introducing classNames and styles props—backed by a new useMergeSemantic hook—across various input-related components and their demos/tests.
- Introduce and integrate
classNames/stylesprops for Input, TextArea, Search, OTPInput, and Password. - Update demos (
_semantic_*.tsx) to showcase semantic elements. - Extend
ConfigProviderand tests to cover the new semantic APIs.
Reviewed Changes
Copilot reviewed 24 out of 24 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| components/input/demo/_semantic_password.tsx | Add semantic-preview demo for Password input |
| components/input/demo/_semantic_otp.tsx | Add semantic-preview demo for OTP input |
| components/input/demo/_semantic_input.tsx | Add root semantic element and version bump to Input demo |
| components/input/tests/textarea.test.tsx | Add classNames/styles tests for TextArea |
| components/input/tests/otp.test.tsx | Add classNames/styles tests for OTPInput |
| components/input/tests/index.test.tsx | Add classNames/styles tests for Input |
| components/input/tests/Search.test.tsx | Add classNames/styles tests for Search |
| components/input/tests/Password.test.tsx | Add classNames/styles tests for Password |
| components/input/TextArea.tsx | Integrate semantic props in TextArea component |
| components/input/Search.tsx | Integrate semantic props in Search component |
| components/input/OTP/index.tsx | Integrate semantic props in OTPInput component |
| components/input/Input.tsx | Integrate semantic props in Input component |
| components/config-provider/index.tsx | Extend ConfigProvider with search and otpInput config |
| components/config-provider/context.ts | Extend context types for Search and OTPInput |
| components/button/button.tsx | Export ButtonSemanticName and support semantic props in Button |
Comments suppressed due to low confidence (1)
components/button/tests/index.test.tsx:518
- [nitpick] Typo in variable name
cusomStyles; consider renaming tocustomStylesfor clarity and consistency.
const cusomStyles = {
|
Hi @aojunhao123. Thanks for your contribution. The path |
There was a problem hiding this comment.
Pull Request Overview
This PR adds semantic DOM support to the Input component by introducing classNames and styles props across Input variants, updating demos and documentation, and extending configuration and tests to cover semantic class/style injection.
- Introduce
classNames&stylesprops and merge logic (useMergeSemantic) in Input, TextArea, Search, and OTP components - Update documentation (
index.zh-CN.md,index.en-US.md) and semantic demos for all Input variants - Add semantic DOM tests and update snapshots; extend
ConfigProviderto includesearchandotpInputsettings
Reviewed Changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| components/input/index.zh-CN.md | Document classNames/styles and update anchors |
| components/input/index.en-US.md | Same updates for English docs |
| components/input/demo/_semantic_*.tsx | Add demos for Input/TextArea/Search/Password/OTP |
| components/input/TextArea.tsx | Merge semantic classes/styles into TextArea |
| components/input/Search.tsx | Merge semantic classes/styles into Search |
| components/input/OTP/index.tsx | Merge semantic classes/styles into OTP |
| components/input/Input.tsx | Merge semantic classes/styles into Input |
| components/input/__tests__/semantic.test.tsx | Add semantic DOM tests for all variants |
| components/config-provider/{index,context}.tsx | Include search and otpInput in config |
| components/button/button.tsx | Add semantic prop types and support in loading icon |
|
|
||
| | Property | Description | Type | Default | Version | | ||
| | --- | --- | --- | --- | --- | | ||
| | classNames | Semantic DOM class | Record<[SemanticDOM](#semantic-password), string> | - | | |
There was a problem hiding this comment.
The documentation indicates that Input.Password supports classNames and styles, but the Password.tsx implementation wasn’t updated to merge or apply these props. Please update Password.tsx to use useMergeSemantic and pass semantic classNames/styles to its elements.
|
@coderabbitai 嘿兔子,帮忙仔细review 一下这个pr,每个文件都看看。 |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain@thinkasany 好的!我来仔细review一下这个PR的每个文件。让我先获取这个PR的详细信息。 让我继续查看具体的实现文件: 现在检查其他关键组件的实现: 让我查看测试文件确保测试覆盖度: 查看demo文件了解语义化DOM的具体用法: 最后检查文档更新: 📋 PR Review 总结这是一个为Ant Design输入组件添加语义化DOM支持的重要PR。以下是我的详细review: 🎯 主要功能
✅ 实现质量评估优点:
需要注意的点:
🔍 代码质量检查配置类型定义:
组件实现:
测试覆盖:
🚀 建议
📊 整体评价这是一个高质量的PR,实现了重要的语义化DOM功能:
总的来说,这个PR为Ant Design的输入组件带来了很有价值的语义化支持,建议在确认视觉回归后可以合并。 🐰✨ 🏁 Script executed: Length of output: 449 🏁 Script executed: Length of output: 12134 🏁 Script executed: Length of output: 22944 🏁 Script executed: Length of output: 3382 🏁 Script executed: Length of output: 3307 🏁 Script executed: Length of output: 3105 @thinkasany 我已经仔细review了这个PR的每个文件!这是一个为Ant Design输入组件添加语义化DOM支持的重要功能。以下是我的详细分析: 🎯 功能概述这个PR为以下组件添加了语义化DOM支持:
每个组件现在都支持通过 ✅ 实现质量评估代码结构 - 优秀
语义化结构设计 - 合理// Input组件的语义结构
type SemanticName = 'root' | 'prefix' | 'suffix' | 'input' | 'count';
// Search组件扩展了button语义
classNames?: Partial<Record<SemanticName, string>> & {
button?: Partial<Record<ButtonSemanticName, string>>;
};
// OTP组件独特的分隔符支持
type SemanticName = 'root' | 'input' | 'separator';配置提供者集成 - 完善在 🧪 测试覆盖 - 完整每个组件都有对应的语义化测试:
📚 文档质量 - 优秀
|
|
@coderabbitai,直接评论代码,给出推荐的建议代码,和指出不合适的代码。 |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain@thinkasany 我来深入分析代码并提供具体的建议和问题指出。让我仔细检查实现细节: 基于代码分析,我发现以下需要改进的地方: 🚨 需要改进的代码1. Input.tsx - 性能优化问题问题代码: const [mergedClassNames, mergedStyles] = useMergeSemantic(
[contextClassNames, classNames],
[contextStyles, styles],
);问题: 每次渲染都会创建新的数组,可能导致不必要的重新计算。 建议代码: const [mergedClassNames, mergedStyles] = useMergeSemantic(
useMemo(() => [contextClassNames, classNames], [contextClassNames, classNames]),
useMemo(() => [contextStyles, styles], [contextStyles, styles]),
);2. Search.tsx - 嵌套样式结构复杂问题代码: classNames?: Partial<Record<SemanticName, string>> & {
button?: Partial<Record<ButtonSemanticName, string>>;
};问题: 类型结构过于复杂,不利于维护和理解。 建议代码: interface SearchClassNames extends Partial<Record<SemanticName, string>> {
button?: Partial<Record<ButtonSemanticName, string>>;
}
interface SearchProps {
classNames?: SearchClassNames;
// ...其他props
}3. OTP组件 - 缺少错误边界问题代码: {new Array(length).fill(null).map((_, index) => (
<OTPInput key={index} index={index} {...inputProps} />
))}问题: 直接使用 建议代码: {Array.from({ length: Math.max(0, Math.min(length || 0, 10)) }, (_, index) => (
<OTPInput key={index} index={index} {...inputProps} />
))}✅ 推荐的代码模式1. 统一的语义化Hook封装推荐代码: // 创建通用的语义化Hook
function useInputSemantic<T extends Record<string, any>>(
contextConfig: any,
componentConfig: any,
) {
return useMemo(() =>
useMergeSemantic([contextConfig, componentConfig]),
[contextConfig, componentConfig]
);
}
// 在组件中使用
const [mergedClassNames, mergedStyles] = useInputSemantic(
{ classNames: contextClassNames, styles: contextStyles },
{ classNames, styles }
);2. 更好的类型安全性推荐代码: // 在 context.ts 中
interface SemanticToken<T extends string> {
classNames?: Partial<Record<T, string>>;
styles?: Partial<Record<T, CSSProperties>>;
}
type InputSemanticName = 'root' | 'prefix' | 'suffix' | 'input' | 'count';
type InputToken = SemanticToken<InputSemanticName>;3. 组件属性验证推荐代码: const Input = React.forwardRef<InputRef, InputProps>((props, ref) => {
// 属性验证
if (process.env.NODE_ENV !== 'production') {
if (props.classNames && typeof props.classNames !== 'object') {
console.warn('Input: classNames should be an object');
}
}
// 组件逻辑...
});🔍 代码质量问题1. 缺少JSDoc注释/**
* Input component with semantic DOM support
* @param classNames - Custom class names for semantic elements
* @param styles - Custom styles for semantic elements
*/
interface InputProps {
classNames?: Partial<Record<SemanticName, string>>;
styles?: Partial<Record<SemanticName, CSSProperties>>;
}2. 测试覆盖不够深入当前测试只检查快照,建议增加: it('should apply semantic styles correctly', () => {
const customStyles = {
root: { backgroundColor: 'red' },
input: { color: 'blue' }
};
render(<Input styles={customStyles} />);
expect(document.querySelector('.ant-input-affix-wrapper')).toHaveStyle({
backgroundColor: 'red'
});
});3. 条件渲染可以优化当前代码: {prefix && <span className={cls(mergedClassNames.prefix)}>{prefix}</span>}建议: {prefix ? (
<span className={cls(mergedClassNames.prefix)} style={mergedStyles.prefix}>
{prefix}
</span>
) : null}📊 整体代码评价✅ 优点:
|
| 组件 | 当前评分 | 主要问题 | 建议优先级 |
|---|---|---|---|
| Input.tsx | 6/10 | 性能问题、复杂逻辑 | 🔴 高 |
| Search.tsx | 5/10 | 类型安全、条件逻辑 | 🔴 高 |
| TextArea.tsx | 7/10 | 性能优化缺失 | 🟡 中 |
| OTP/index.tsx | 6/10 | 边界检查缺失 | 🟡 中 |
总结: 虽然功能实现正确,但在性能优化、类型安全和代码质量方面还有显著提升空间。建议优先修复性能和类型安全问题。
| | inputNumber | 设置 Input 组件的通用属性 | { className?: string, style?: React.CSSProperties, classNames?: [InputNumberConfig\["classNames"\]](/components/input-number-cn#semantic-dom), styles?: [InputNumberConfig\["styles"\]](/components/input-number-cn#semantic-dom) } | - | | | ||
| | textArea | 设置 TextArea 组件的通用属性 | { autoComplete?: string, className?: string, style?: React.CSSProperties, allowClear?: boolean \| { clearIcon?: ReactNode } } | - | 5.15.0 | | ||
| | otp | 设置 OTP 组件的通用属性 | { className?: string, style?: React.CSSProperties, classNames?: [OTPConfig\["classNames"\]](/components/input-cn#semantic-otp), styles?: [OTPConfig\["styles"\]](/components/input-cn#semantic-otp) } | - | | | ||
| | search | 设置 Search 组件的通用属性 | { className?: string, style?: React.CSSProperties, classNames?: [SearchConfig\["classNames"\]](/components/input-cn#semantic-search), styles?: [SearchConfig\["styles"\]](/components/input-cn#semantic-search) } | - | | |


中文版模板 / Chinese template
🤔 This is a ...
🔗 Related Issues
💡 Background and Solution
📝 Change Log