Skip to content

fix: handle whitespace-only values in content-has-value class#1209

Merged
zombieJ merged 2 commits intomasterfrom
fix/has-value-empty-spacing
Feb 13, 2026
Merged

fix: handle whitespace-only values in content-has-value class#1209
zombieJ merged 2 commits intomasterfrom
fix/has-value-empty-spacing

Conversation

@zombieJ
Copy link
Member

@zombieJ zombieJ commented Feb 13, 2026

ref ant-design/ant-design#56966

Summary by CodeRabbit

Bug Fixes

  • 修复了当标签仅包含空白字符时,选择框错误应用"已填充"样式的问题。

@vercel
Copy link

vercel bot commented Feb 13, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
select Ready Ready Preview, Comment Feb 13, 2026 7:10am

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @zombieJ, 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 a UI inconsistency within the SelectInput component where inputs containing only whitespace characters were erroneously treated as having a valid value, leading to the incorrect application of a 'has value' CSS class. The changes ensure that the component accurately reflects the presence of meaningful content, thereby enhancing the visual state and user experience for select inputs by correctly distinguishing between empty and whitespace-only values.

Highlights

  • Refactored Value Check Logic: Introduced a new boolean variable showHasValueCls in SingleContent.tsx to encapsulate the logic for determining if a select input truly has a non-whitespace value, improving readability and maintainability.
  • Corrected CSS Class Application: Modified the clsx utility call in SingleContent.tsx to use the new showHasValueCls variable, ensuring the -content-has-value CSS class is only applied when the selected value contains meaningful, non-whitespace content.
  • Added Unit Test for Whitespace Handling: Included a new unit test in Select.test.tsx to specifically assert that the -content-has-value class is not present when the selected value consists solely of whitespace characters, preventing UI inconsistencies.

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

Changelog
  • src/SelectInput/Content/SingleContent.tsx
    • Refactored the logic for determining if a select input has a value to explicitly exclude whitespace-only strings.
    • Updated the conditional application of the -content-has-value CSS class based on the new whitespace-aware value check.
  • tests/Select.test.tsx
    • Added a new test case to verify that the -content-has-value class is not applied when the selected value is a whitespace string.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 13, 2026

概述

在单值选择输入内容组件中引入了新的布尔常量 showHasValueCls,用于判断显示值是否应被视为"有值"状态,条件包括显示值存在、标签非空以及修剪后的标签非空;同时在测试中添加了关于空白字符串值的新测试用例。

变更

内容聚类 / 文件 摘要
单值内容组件逻辑
src/SelectInput/Content/SingleContent.tsx
引入 showHasValueCls 常量来判定是否应用 content-has-value 样式类,新增对修剪后标签非空的检查,替代原有的内联条件判断。
选择器测试用例
tests/Select.test.tsx
修改现有测试中 Option 的 value 属性从字符串 "1" 改为数字 1;新增测试验证当值为空白字符串时不应用 content-has-value 样式类。

估计代码审查工作量

🎯 2 (简单) | ⏱️ ~10 分钟

可能相关的拉取请求

建议的审查者

  • meet-student

诗歌

🐰 跳跃的小兔,修剪了空白,
标签干净整洁,样式更精准,
空白不再迷茫,逻辑更明快,
测试保驾护航,品质不打折!

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题清晰准确地总结了主要更改,即处理仅包含空格的值对于content-has-value类的处理。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into master

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/has-value-empty-spacing

No actionable comments were generated in the recent review. 🎉

🧹 Recent nitpick comments
src/SelectInput/Content/SingleContent.tsx (1)

66-70: 可选优化:!= null 可合并两个判空检查。

displayValue.label !== null && displayValue.label !== undefined 等价于 displayValue.label != null(宽松等式),可以稍微简化表达。

♻️ 建议的简化写法
   const showHasValueCls =
     displayValue &&
-    displayValue.label !== null &&
-    displayValue.label !== undefined &&
+    displayValue.label != null &&
     String(displayValue.label).trim() !== '';

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link

codecov bot commented Feb 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.43%. Comparing base (3924823) to head (9e09741).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1209   +/-   ##
=======================================
  Coverage   99.43%   99.43%           
=======================================
  Files          31       31           
  Lines        1234     1234           
  Branches      423      445   +22     
=======================================
  Hits         1227     1227           
  Misses          7        7           

☔ 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request fixes an issue where whitespace-only values were incorrectly considered as having content. The change correctly trims the label and checks if it's empty. A test case has been added to cover this scenario. My feedback includes a suggestion to simplify the new logic for better readability.

Comment on lines +66 to +71
const showHasValueCls =
displayValue &&
displayValue.label !== null &&
displayValue.label !== undefined &&
String(displayValue.label).trim() !== '';

Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The logic to determine showHasValueCls can be simplified for better readability. The !! and extra parentheses are redundant, != null can be used to check for both null and undefined, and optional chaining (?.) can make the code more concise.

    const showHasValueCls =
      displayValue?.label != null && String(displayValue.label).trim() !== '';

@zombieJ zombieJ merged commit 19a0c16 into master Feb 13, 2026
12 checks passed
@zombieJ zombieJ deleted the fix/has-value-empty-spacing branch February 13, 2026 07:17
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.

1 participant