Skip to content

fix: use strict null/undefined check for display value in single select#1205

Merged
zombieJ merged 1 commit intomasterfrom
refactor/display-value-check
Feb 12, 2026
Merged

fix: use strict null/undefined check for display value in single select#1205
zombieJ merged 1 commit intomasterfrom
refactor/display-value-check

Conversation

@zombieJ
Copy link
Member

@zombieJ zombieJ commented Feb 12, 2026

Empty string values should be treated as valid values (having a display value), not as missing values. This fixes the content-has-value class not being applied when the value is an empty string.

fix ant-design/ant-design#56973

Summary by CodeRabbit

发行说明

  • Bug 修复

    • 改进了选择组件中显示值的检测逻辑,确保在空字符串等边界情况下能正确处理和渲染值。
  • 测试

    • 增加了新的测试用例,验证组件在特定场景下的 CSS 类应用行为。

Empty string values should be treated as valid values (having a display value),
not as missing values. This fixes the content-has-value class not being applied
when the value is an empty string.

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

vercel bot commented Feb 12, 2026

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

Project Deployment Actions Updated (UTC)
select Ready Ready Preview, Comment Feb 12, 2026 5:23pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 12, 2026

Walkthrough

在 SingleContent.tsx 中引入 hasDisplayValue 守卫变量,用来稳健地检测显示值的存在,取代对 displayValue 的 truthy 检查。该变量被应用于选项数据选择、标题计算、渲染值确定和容器 CSS 类构造等四处。同时添加了测试用例验证空字符串值的样式类应用。

Changes

Cohort / File(s) Summary
核心逻辑改动
src/SelectInput/Content/SingleContent.tsx
引入 hasDisplayValue 守卫变量替换 displayValue 的 truthy 检查,应用于选项数据选择、标题计算、渲染值和 CSS 类构造,明确处理 null/undefined 情况。
新增测试
tests/placeholder.test.tsx
添加测试用例验证 Select 组件在 value="" 时正确应用 content-has-value CSS 类。

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested reviewers

  • meet-student

Poem

🐰 空字符串不再捣蛋,
hasDisplayValue 来把关,
高度稳稳保持住,
样式类恰到好处,
测试守护品质翠。

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed Pull request title clearly and specifically describes the main change: introducing strict null/undefined checks for display value in single select component.
Linked Issues check ✅ Passed The code changes directly address issue #56973 by introducing hasDisplayValue guard to treat empty strings as valid display values, ensuring content-has-value class is applied correctly.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the display value check issue; modifications to SingleContent.tsx and addition of placeholder.test.tsx are both in scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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 refactor/display-value-check

No actionable comments were generated in the recent review. 🎉

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

22-22: 可以考虑用宽松等式简化空值检查。

displayValue !== null && displayValue !== undefined 等价于 displayValue != null,后者是 JavaScript/TypeScript 中常见的惯用写法,更简洁。

♻️ 可选简化
-    const hasDisplayValue = displayValue !== null && displayValue !== undefined;
+    const hasDisplayValue = displayValue != null;

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 12, 2026

Codecov Report

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

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1205   +/-   ##
=======================================
  Coverage   99.43%   99.43%           
=======================================
  Files          31       31           
  Lines        1230     1231    +1     
  Branches      441      420   -21     
=======================================
+ Hits         1223     1224    +1     
  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.

@zombieJ zombieJ merged commit f781118 into master Feb 12, 2026
12 checks passed
@zombieJ zombieJ deleted the refactor/display-value-check branch February 12, 2026 17:27
@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 fixes a rendering bug in the single select component where an empty string value was not recognized as a valid selection, leading to incorrect CSS class application. By implementing a more precise check for the presence of a display value, the component now correctly applies the content-has-value class for all non-null and non-undefined values, including empty strings, thus improving visual consistency and user experience.

Highlights

  • Bug Fix: Resolved an issue where empty string values were not correctly treated as valid display values in the single select component, preventing the content-has-value class from being applied.
  • Improved Display Value Check: Introduced a new variable hasDisplayValue that strictly checks if displayValue is not null or undefined, ensuring empty strings are considered valid values.
  • Test Coverage: Added a new test case to verify that the content-has-value class is correctly applied when the select component's value is an empty string.

🧠 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
    • Introduced a new hasDisplayValue variable to strictly check for null or undefined display values.
    • Updated conditional logic for rendering and class application to use hasDisplayValue instead of direct displayValue truthiness.
  • tests/placeholder.test.tsx
    • Added a test case to confirm that the .rc-select-content-has-value class is present when the Select component has an empty string as its value.
Activity
  • A summary was auto-generated by coderabbit.ai, highlighting the bug fix in the select component's display value detection and the addition of new test cases for CSS class application.
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.

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 addresses a bug where empty string values in the single select component were not being treated as valid, leading to incorrect rendering. The change to use a strict check for null and undefined to determine the presence of a display value is the correct approach, as it properly handles falsy values like empty strings. The introduction of the hasDisplayValue constant is a good refactoring that improves code clarity and maintainability. Additionally, the new test case effectively verifies the fix. The changes are well-implemented and resolve the reported issue.

zombieJ added a commit that referenced this pull request Feb 12, 2026
zombieJ added a commit that referenced this pull request Feb 12, 2026
zombieJ added a commit that referenced this pull request Feb 12, 2026
* Revert "fix: use strict null/undefined check for display value in single select (#1205)"

This reverts commit f781118.

* fix: check displayValue label before adding -content-has-value className

Ensures the -content-has-value className is only added when displayValue has a truthy label property, preventing the class from being added when value is empty or null.

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

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
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.

Select height is not right when value=""

1 participant