fix(ColorPicker): restrict HEX input to valid hex characters#56752
fix(ColorPicker): restrict HEX input to valid hex characters#56752zombieJ merged 4 commits intoant-design:masterfrom
Conversation
|
|
Summary of ChangesHello @treephesians, 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 resolves an issue in the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe 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
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 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
|
👁 Visual Regression Report for PR #56752 Passed ✅
🎊 Congrats! No visual-regression diff found.
|
📝 WalkthroughSummary by CodeRabbit发布说明
✏️ Tip: You can customize this high-level summary in your review settings. Walkthrough更新 ColorPicker 的十六进制输入规范化逻辑,正则由 Changes
Sequence Diagram(s)(无序列图 — 更改局限于单一输入过滤函数,未引入跨组件的新流程。) Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 分钟 Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Code Review
This pull request correctly fixes an issue where the ColorPicker's HEX input allowed invalid characters. The change in color.ts to use a stricter regular expression is appropriate and effectively solves the problem, and the corresponding test update is also correct. While reviewing, I noticed a potential pre-existing issue in ColorHexInput.tsx regarding inconsistent handling of hex values with alpha, which could lead to a UI-state mismatch. I recommend addressing this in a separate PR as it's outside the scope of these changes.
More templates
commit: |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #56752 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 807 807
Lines 14923 14923
Branches 3931 3931
=========================================
Hits 14923 14923 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Bundle ReportChanges will increase total bundle size by 8 bytes (0.0%) ⬆️. 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
|
|
@gemini-code-assist Pls help to CR again. |
There was a problem hiding this comment.
Code Review
This pull request correctly fixes an issue where the ColorPicker's HEX input allowed invalid characters. The fix, which involves tightening a regular expression, is appropriate and effective. The accompanying test changes validate the new behavior. I have one suggestion to improve the readability and remove redundancy in the test code.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Signed-off-by: 二货爱吃白萝卜 <smith3816@gmail.com>



🤔 This is a ...
🔗 Related Issues
fix #56740
💡 Background and Solution
Background
The HEX input in
ColorPickercurrently allows characters that are not valid hexadecimal digits (such as_or/) during typing.This behavior is caused by overly permissive input normalization, which results in invalid characters being displayed in the input field without triggering
onChange.This can be confusing for users, as the input visually accepts values that are not valid HEX colors.
Solution
The input normalization logic has been updated to strictly allow only valid hexadecimal characters (
0-9,a-f,A-F).This ensures that the HEX input value always stays within the valid character set during typing.
Additional test cases have been added to cover this behavior and prevent regressions.
No public API changes are introduced.
📝 Change Log