Skip to content

Conversation

@barangezen
Copy link

@barangezen barangezen commented Feb 1, 2026

🤔 This is a ...

  • 🐞 Bug fix

🔗 Related Issues
Fixes: ant-design/ant-design#56735

Problem

When notFoundContent={null} and showSearch is enabled, typing a character with no matching options causes the input to immediately clear.

Solution

The useEffect that clears searchValue on dropdown close was triggering even when emptyListContent prevented the dropdown from opening.

Fixed by tracking previous open state via ref - only clear searchValue when dropdown actually closes (was open → now closed), not when it was never opened.

Test Plan

  • Added test case
  • All 392 tests pass

Summary by CodeRabbit

  • Bug Fixes

    • 改进下拉菜单关闭逻辑:在非多选、非组合框且无匹配内容时避免清空搜索输入,提升输入在强制关闭场景下的稳定性。
  • Tests

    • 新增测试覆盖:验证在 notFoundContent 为 null 且无匹配项时的输入与搜索回调行为,确保输入值和搜索事件按预期保留与触发。

✏️ Tip: You can customize this high-level summary in your review settings.

…tions match

When notFoundContent is null and search yields no matching options,
the search input was immediately clearing typed characters.

Root cause: The useEffect that clears searchValue on dropdown close
was triggering even when the dropdown was forced closed by emptyListContent,
not from an actual user close action.

Fix: Track the previous open state and emptyListContent via refs.
Only clear searchValue when the dropdown was actually open before
and emptyListContent is not preventing the dropdown from showing.

Co-authored-by: Cursor <cursoragent@cursor.com>
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @barangezen, 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 specific bug in the BaseSelect component that caused the search input to clear unexpectedly when notFoundContent was set to null and a search yielded no results. The change ensures that the search input's value is preserved, allowing users to continue typing even when no matches are found, thereby improving the search experience and component robustness.

Highlights

  • Bug Fix: Search Input Unresponsiveness: Implemented a fix for the BaseSelect component where the search input would become unresponsive and clear its value prematurely when notFoundContent was null and no matching options were found.
  • Refined Dropdown Closure Logic: Modified the useEffect hook responsible for clearing the search value to correctly differentiate between a genuine dropdown closure and a forced closure due to emptyListContent.
  • State Tracking with useRef: Introduced useRef hooks (emptyListContentRef and prevOpenRef) to accurately track the dropdown's previous open state and the emptyListContent status, preventing premature clearing of the search input.
  • New Test Case Added: Added a new test case to validate the corrected behavior, ensuring the search input remains functional even when no options match and notFoundContent is null.

🧠 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 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 1, 2026

Walkthrough

引入两个 ref(emptyListContentRefprevOpenRef),调整 BaseSelect 的关闭处理逻辑:仅在下拉从打开变为关闭且非多选/非 combobox 且 emptyListContent 为 false 时清理搜索输入;新增测试覆盖 notFoundContentnull 时的输入行为场景。

Changes

Cohort / File(s) Summary
BaseSelect 核心逻辑修复
src/BaseSelect/index.tsx
新增 emptyListContentRefprevOpenRef,修改关闭时的 effect 条件以仅在真正从打开→关闭且非多选/非 combobox 且 emptyListContent 为 false 时触发清理逻辑;保留并更新前一次 open 状态。
搜索交互测试
tests/Select.test.tsx
新增测试用例(重复插入于两个位置)验证当 notFoundContentnull 且开启 showSearch 时,输入不同字符(匹配/不匹配/连续输入)时输入框应正常接收并显示全部输入且触发 onSearch

Sequence Diagram(s)

sequenceDiagram
    participant User as User
    participant Select as BaseSelect
    participant Dropdown as DropdownList
    participant Effect as CloseEffect

    User->>Select: 输入字符 (onSearch, update input)
    Select->>Dropdown: 过滤 options 并渲染
    Dropdown-->>Select: emptyListContent = true/false
    Note right of Select: prevOpenRef 保存前一次 open 状态
    Select->>Effect: open 从 true 变为 false
    Effect->>Select: 如果非 multi/combobox 且 emptyListContent == false -> 清理搜索
    Effect-->>Select: 否则 不清理(保留输入)
Loading

Estimated code review effort

🎯 3 (中等复杂) | ⏱️ ~20 分钟

Possibly related PRs

Suggested reviewers

  • afc163
  • zombieJ

Poem

🐰 我在草丛中轻敲键盘,
搜索的字母不再被风吹跑,
Refs 站岗守护每一行输入,
下拉若顽皮也不偷走音调,
Select 与用户再次并肩跳跃 🌟

🚥 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 标题清晰准确地描述了主要修复内容:当notFoundContent为null时搜索输入无响应的问题。
Linked Issues check ✅ Passed 代码变更完全满足关联问题的要求:修复了搜索输入仅显示最后一个字符的bug,并添加了相应的测试用例。
Out of Scope Changes check ✅ Passed 所有代码变更都与修复搜索输入响应问题直接相关,包括refs引入、效果流程调整和新增测试,无超出范围的更改。
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

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.

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 effectively resolves an issue where the search input would incorrectly clear when notFoundContent is set to null and no search results are found. The solution correctly uses useRef to track the previous open state of the dropdown and to access the emptyListContent flag without adding it as a useEffect dependency. This ensures the search value is only cleared when the dropdown is intentionally closed by the user, not when it's hidden due to a lack of matching options. A new test case has been added that accurately covers the bug scenario, confirming the fix. The changes are well-implemented and improve the user experience for the search functionality.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@tests/Select.test.tsx`:
- Around line 2000-2001: Update the placeholder issue URL in the test comment so
it references the real issue: replace the comment line "//
https://github.com/react-component/select/issues/XXX" with the correct issue
link (for example "https://github.com/ant-design/ant-design/issues/56735" or the
actual react-component/select issue number) near the test case "should allow
typing when notFoundContent is null and no options match" in Select.test.tsx;
ensure the updated comment accurately reflects the relevant repository and issue
number.

@vercel
Copy link

vercel bot commented Feb 1, 2026

@barangezen is attempting to deploy a commit to the React Component Team on Vercel.

A member of the Team first needs to authorize it.

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.

Unable to enter search query into searchable select when notFoundContent is set to null

1 participant