Skip to content

Conversation

@barangezen
Copy link

@barangezen barangezen commented Feb 1, 2026

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

Summary by CodeRabbit

发行说明

  • 问题修复
    • 修复了下拉框关闭时搜索文本被意外清除的问题
    • 优化了无匹配结果场景下的搜索行为,防止用户输入被意外丢失

✏️ 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>
@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.

@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 bug in the BaseSelect component where the search input would prematurely clear its value, making it unresponsive, when a search yielded no results and the notFoundContent prop was set to null. The fix ensures that the search input's value is only cleared upon a genuine user-initiated dropdown closure, preventing unintended clearing when the dropdown is merely suppressed due to lack of matching options.

Highlights

  • Problem Addressed: Fixed an issue where the search input in the BaseSelect component would become unresponsive and clear typed characters when notFoundContent was null and no options matched the search query.
  • Root Cause Identified: The useEffect responsible for clearing the search value on dropdown close was incorrectly triggering when the dropdown was forced closed due to emptyListContent (no matching options), rather than an explicit user-initiated close.
  • Solution Implemented: Introduced useRef hooks (emptyListContentRef and prevOpenRef) to accurately track the previous open state and the emptyListContent status. The search value is now only cleared if the dropdown genuinely transitions from an open to a closed state and emptyListContent is not preventing it from showing.
  • Test Coverage: A new test case has been added to tests/Select.test.tsx to specifically verify that typing is allowed and the input remains responsive under the conditions where notFoundContent is null and no options match.

🧠 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

Caution

Review failed

The pull request is closed.

Walkthrough

针对下拉菜单关闭时清除搜索值的行为进行了条件化防卫。新增逻辑通过追踪前一个打开状态和空列表内容标志,仅在下拉菜单真正关闭且未因搜索结果为空而被强制关闭时才清除搜索文本。同时添加了相应的测试用例。

Changes

Cohort / File(s) Summary
搜索值清除防卫逻辑
src/BaseSelect/index.tsx
引入 prevOpenRef 用于检测实际的关闭事件,添加 emptyListContentRef 用于追踪下拉菜单是否因搜索结果为空而被强制关闭,并条件化地调用 onInternalSearch 清除搜索值。
下拉菜单搜索行为测试
tests/Select.test.tsx
添加测试用例验证当 notFoundContent 为 null 且无选项匹配时,用户可继续输入;确保每次更改后 onSearch 被调用且输入值更新正常。

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • afc163
  • zombieJ

Poem

🐰 搜索框的小秘密,
守卫它不再误删,
关闭时细心把关,
空列表也有温柔,
输入不再惊慌张,
测试验证小心思!✨

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

@barangezen barangezen closed this Feb 1, 2026
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 become unresponsive when notFoundContent is null and no options match the search query. The fix correctly uses useRef to track the previous open state and whether the dropdown is empty, preventing the search value from being cleared incorrectly. The logic is sound and well-commented. Additionally, a comprehensive test case has been added to verify the fix and prevent future regressions. I have one suggestion to improve the test's maintainability.

expect(container.querySelector('.rc-select-dropdown-empty')).toBeFalsy();
});

// https://github.com/react-component/select/issues/XXX
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

To improve maintainability, please replace the placeholder XXX in the issue link with the actual GitHub issue number that this change resolves. This provides valuable context for future developers.

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