Skip to content

fix: fix the issue that ColorHexInput cannot manually input values ​​caused by #53810#53814

Merged
afc163 merged 4 commits intoant-design:masterfrom
DDDDD12138:fix/color-hex-input
May 14, 2025
Merged

fix: fix the issue that ColorHexInput cannot manually input values ​​caused by #53810#53814
afc163 merged 4 commits intoant-design:masterfrom
DDDDD12138:fix/color-hex-input

Conversation

@DDDDD12138
Copy link
Copy Markdown
Contributor

@DDDDD12138 DDDDD12138 commented May 13, 2025

中文版模板 / Chinese template

🤔 This is a ...

  • 🐞 Bug fix

🔗 Related Issues

fix #53810

💡 Background and Solution

This commit reverts the changes made in commit 4bc93c3 to ColorHexInput.tsx.
The previous change replaced the hexValue state with a computed property, which caused the input to become unresponsive.

📝 Change Log

Language Changelog
🇺🇸 English Fix ColorPicker's hex input field not accepting user input
🇨🇳 Chinese 修复 ColorPicker 的十六进制输入框无法输入的问题

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

📝 Walkthrough

Summary by CodeRabbit

  • 测试
    • 新增了针对颜色十六进制输入组件的测试用例,验证了输入值随外部属性变化的同步效果,以及用户输入时的行为和回调触发条件。
      """

Summary by CodeRabbit

  • 优化
    • 改进了色值输入框的同步逻辑,确保输入内容与外部数值和内部编辑保持一致,提升了用户体验和输入准确性。

Walkthrough

本次变更重构了 ColorHexInput 组件的内部状态管理方式,使用 useEffect 钩子同步外部 value 属性与内部 hexValue 状态,并优化了输入处理逻辑,确保输入框显示的颜色值与外部属性和用户输入保持一致。

Changes

文件/路径 变更摘要
components/color-picker/components/ColorHexInput.tsx 重命名内部状态变量,新增 useEffect 同步外部 value,优化输入处理逻辑,确保状态唯一来源。
components/color-picker/tests/components.test.tsx 新增 ColorHexInput 组件的测试,验证外部 value 变化更新输入显示及用户输入处理逻辑。

Sequence Diagram(s)

sequenceDiagram
    participant Parent as 父组件
    participant ColorHexInput as ColorHexInput组件
    Parent->>ColorHexInput: 传递 value 属性
    ColorHexInput->>ColorHexInput: useEffect 监听 value,格式化并设置 hexValue
    User->>ColorHexInput: 输入新颜色值
    ColorHexInput->>ColorHexInput: 更新 hexValue
    ColorHexInput-->>Parent: onChange(仅当输入为有效 hex 时)
Loading

Assessment against linked issues

Objective Addressed Explanation
弹出层输入框能够正常更改颜色值 (#53810)

Possibly related PRs

Suggested labels

lgtm

Suggested reviewers

  • zombieJ

Poem

兔子敲代码,颜色随手改,
Hex 值同步,Bug 也不在。
输入框里新色彩,
组件状态真可爱!
🐇✨
"""

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.


📜 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 13092fd and d944572.

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

9-9: 新增了 generateColor 导入

导入了 generateColor 工具函数,该函数在新增的测试用例中用于生成颜色对象。这是合理的变更,支持后续新增的测试用例。


99-130: 很好的测试用例,验证了外部值变化时输入框的更新机制

这个测试用例验证了当 value 属性从外部变化时,ColorHexInput 组件能够正确更新其显示值。测试通过以下步骤验证了组件的行为:

  1. 使用初始颜色渲染组件
  2. 验证输入框显示正确的十六进制值
  3. 使用新的颜色值重新渲染组件
  4. 验证输入框值已更新为新的颜色值

这个测试直接对应了 PR 修复的问题,确保了十六进制输入框能够正确响应外部属性变化。


132-156: 很好的测试用例,验证了用户输入的处理逻辑

这个测试用例验证了 ColorHexInput 组件如何正确处理用户输入并维护其内部状态。测试涵盖了:

  1. 有效输入的处理(触发 onChange 回调)
  2. 无效输入的处理(不触发 onChange 回调,但仍更新显示值)

这个测试很好地覆盖了组件的核心功能,尤其是验证了 PR 修复的问题 - 十六进制输入框现在可以接受用户输入并正确处理。

测试还验证了一个重要的边界情况:当用户输入无效值时,组件应该更新显示值但不触发 onChange 回调,这符合受控组件的最佳实践。

✨ Finishing Touches
  • 📝 Generate Docstrings

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

@petercat-assistant
Copy link
Copy Markdown

Walkthrough

This pull request reverts previous changes to the ColorHexInput.tsx component that caused input issues. The changes had replaced the hexValue state with a computed property, leading to unresponsive input behavior. The reversion aims to restore the original functionality.

Changes

File Summary
components/color-picker/components/ColorHexInput.tsx Reverted changes to use hexValue state instead of a computed property, added useEffect to update hexValue when value changes, and removed internalValue state.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 13, 2025

👁 Visual Regression Report for PR #53814 Passed ✅

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

🎊 Congrats! No visual-regression diff found.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 13, 2025

Preview is ready

const ColorHexInput: FC<ColorHexInputProps> = ({ prefixCls, value, onChange }) => {
const colorHexInputPrefixCls = `${prefixCls}-hex-input`;
const [internalValue, setInternalValue] = useState('');
const [hexValue, setHexValue] = useState(() =>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The reversion to using hexValue state instead of a computed property is crucial to restoring the input's responsiveness. The previous implementation caused issues with input handling.

@coderabbitai coderabbitai Bot requested a review from zombieJ May 13, 2025 03:42
@coderabbitai coderabbitai Bot added the lgtm This PR has been approved by a maintainer label May 13, 2025
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 13, 2025

@codecov
Copy link
Copy Markdown

codecov Bot commented May 13, 2025

Bundle Report

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

Detailed changes
Bundle name Size Change
antd.min-array-push 3.39MB 130 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 65 bytes 1.85MB 0.0%
antd.min.js 65 bytes 1.54MB 0.0%

@yoyo837
Copy link
Copy Markdown
Contributor

yoyo837 commented May 13, 2025

纯 revert 没有多余改动哈?

@yoyo837
Copy link
Copy Markdown
Contributor

yoyo837 commented May 13, 2025

changelog写一下

@yoyo837
Copy link
Copy Markdown
Contributor

yoyo837 commented May 13, 2025

纯 revert 没有多余改动哈?

原PR #53701 看上去有5个文件,你这是修复吧?不算revert吧?

@codecov
Copy link
Copy Markdown

codecov Bot commented May 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (a07d6f1) to head (21b1840).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master    #53814   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          774       774           
  Lines        14012     14015    +3     
  Branches      3711      3712    +1     
=========================================
+ Hits         14012     14015    +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.

@DDDDD12138
Copy link
Copy Markdown
Contributor Author

changelog写一下

好了

thinkasany
thinkasany previously approved these changes May 14, 2025
Comment thread components/color-picker/components/ColorHexInput.tsx
@thinkasany thinkasany requested a review from afc163 May 14, 2025 09:54
@afc163
Copy link
Copy Markdown
Member

afc163 commented May 14, 2025

好像不是 revert?

@DDDDD12138
Copy link
Copy Markdown
Contributor Author

好像不是 revert?

我只还原了 ColorHexInput.tsx 这一个文件

@afc163 afc163 merged commit 161b0f5 into ant-design:master May 14, 2025
39 checks passed
@yoyo837 yoyo837 changed the title fix: revert changes to ColorHexInput to fix input issues fix: fix ColorHexInput to fail to manually input values cause by #53810 May 14, 2025
@yoyo837 yoyo837 changed the title fix: fix ColorHexInput to fail to manually input values cause by #53810 fix: fix the issue that ColorHexInput cannot manually input values ​​caused by #53810 May 14, 2025
EmilyyyLiu pushed a commit to EmilyyyLiu/ant-design that referenced this pull request May 15, 2025
@PeachScript PeachScript mentioned this pull request May 19, 2025
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.

ColorPicker的弹出层的颜色无法通过输入更改

5 participants