Skip to content

fix: Select with `` value#1207

Merged
zombieJ merged 3 commits intomasterfrom
fix-value
Feb 12, 2026
Merged

fix: Select with `` value#1207
zombieJ merged 3 commits intomasterfrom
fix-value

Conversation

@zombieJ
Copy link
Member

@zombieJ zombieJ commented Feb 12, 2026

fix ant-design/ant-design#56973

Summary by CodeRabbit

Bug Fixes

  • 修复了 Select 输入框的"已填充值"状态指示器的判断逻辑,确保仅在存在有效值时才应用相应的样式类。当输入框值为空时,相关 CSS 类不再被错误应用。

zombieJ and others added 3 commits February 13, 2026 01:43
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>
@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:53pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 12, 2026

Caution

Review failed

The pull request is closed.

概述

修复了 SingleContent.tsx 中的条件类名逻辑,将 "-content-has-value" 修饰符的应用条件从 displayValue 存在改为需要 displayValue.label 存在,同时添加了相应的测试用例验证空值场景。

变更

Cohort / File(s) 摘要
生产代码修复
src/SelectInput/Content/SingleContent.tsx
收紧了 wrapper div 的条件类名判断逻辑,从检查 displayValue 存在改为检查 displayValue.label 存在,确保仅当标签值存在时才应用 "-content-has-value" CSS 类,解决空值场景下的高度问题。
测试覆盖增强
tests/Select.test.tsx
新增测试用例,验证当 Select 的 value prop 为空字符串时,"-content-has-value" className 不被应用,与现有非空值测试形成镜像覆盖。

预估代码审查工作量

🎯 2 (Simple) | ⏱️ ~12 分钟

可能相关的 PR

  • PR#1205: 同样修改 src/SelectInput/Content/SingleContent.tsx 中的 displayValue 检查逻辑,并调整 "-content-has-value" 类的应用时机。
  • PR#1196: 修改 src/SelectInput/Content/SingleContent.tsx 的条件类名逻辑,对根容器的 CSS 类条件进行调整。
  • PR#1195: 修改 SingleContent.tsx 的单选内容与容器渲染逻辑,包括值、标签和标题相关的处理。

建议审查人

  • meet-student

🐰 空值的高度曾困扰,
标签判断现已改造,
条件收紧显精妙,
测试覆盖添周全,
Select 风采更美好!✨

✨ 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-value

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.

@zombieJ zombieJ merged commit 20d5ef1 into master Feb 12, 2026
11 of 12 checks passed
@zombieJ zombieJ deleted the fix-value branch February 12, 2026 17:54
@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 (95fea7c) to head (2acee5c).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1207   +/-   ##
=======================================
  Coverage   99.43%   99.43%           
=======================================
  Files          31       31           
  Lines        1230     1230           
  Branches      419      441   +22     
=======================================
  Hits         1223     1223           
  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.

@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 styling bug within the Select component where an empty string value was erroneously interpreted as a filled input, leading to the application of an incorrect CSS class. The changes refine the condition for applying the "has value" styling, ensuring it only activates when a legitimate value is present, thereby enhancing the visual accuracy and consistency of the component's state.

Highlights

  • Bug Fix: Corrected an issue in the Select component where the rc-select-content-has-value class was incorrectly applied when the input value was an empty string.
  • Conditional Logic Update: Modified the logic in SingleContent.tsx to check for displayValue.label in addition to displayValue before applying the "has value" CSS class.
  • Test Coverage: Introduced a new test case in Select.test.tsx to ensure the rc-select-content-has-value class is not present when the Select component has an empty string as its value.

🧠 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
    • Modified the condition for applying the rc-select-content-has-value class to explicitly check for displayValue.label to prevent incorrect styling when displayValue is an empty string.
  • tests/Select.test.tsx
    • Added a new test case to assert that the rc-select-content-has-value class is not present on a Select component when its value prop is an empty string.
Activity
  • No specific activity (comments, reviews, progress updates) has been recorded for this pull request beyond its initial creation.
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 PR aims to fix the issue where the Select component's style incorrectly displays as having a value when its value is an empty string. While the changes in SingleContent.tsx address this, they introduce a new bug where the numeric value 0 is also incorrectly treated as empty. I've provided a suggestion for this. Please also add a test case for value={0} to prevent similar regressions.

className={clsx(
`${prefixCls}-content`,
displayValue && `${prefixCls}-content-has-value`,
displayValue && displayValue.label && `${prefixCls}-content-has-value`,
Copy link
Contributor

Choose a reason for hiding this comment

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

high

目前的条件 displayValue && displayValue.label 会错误地将 0 视为假值,这意味着当 Select 的值为 0 时,.rc-select-content-has-value 这个 class 不会被应用,可能导致样式不正确。

一个更完善的条件应该能确保 0 被视为有效标签,同时正确处理空字符串的情况。

Suggested change
displayValue && displayValue.label && `${prefixCls}-content-has-value`,
displayValue && (displayValue.label || displayValue.label === 0) && `${prefixCls}-content-has-value`,

Comment on lines +276 to +283
it('should not add -content-has-value className when value is empty string', () => {
const { container } = render(
<Select value="">
<Option value="1">One</Option>
</Select>,
);
expect(container.querySelector('.rc-select-content-has-value')).toBeFalsy();
});
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

针对空字符串值的测试用例很好。为了防止回归并确保数值 0 被正确处理,建议也为 value={0} 添加一个测试用例。SingleContent.tsx 中当前的修复存在一个 bug,即 0 会被视为一个空值。在修复该问题后,添加如下测试用例会很有价值:

  it('should add -content-has-value className when value is 0', () => {
    const { container } = render(
      <Select value={0}>
        <Option value={1}>One</Option>
      </Select>,
    );
    expect(container.querySelector('.rc-select-content-has-value')).toBeTruthy();
  });

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