fix: prevent onSelect firing twice on Enter when dropdown is open#1219
fix: prevent onSelect firing twice on Enter when dropdown is open#1219zombieJ merged 3 commits intoreact-component:masterfrom
Conversation
|
@QDyanbing is attempting to deploy a commit to the React Component Team on Vercel. A member of the Team first needs to authorize it. |
Summary of ChangesHello, 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! 此拉取请求旨在解决 Highlights
🧠 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
Using Gemini Code AssistThe 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
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 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
|
Walkthrough在标签模式(mode="tags")下,Enter 提交的额外前置条件:仅在下拉列表关闭时才会触发 onSearchSubmit;新增测试验证在下拉打开时按 Enter 选择选项只触发 onSelect 一次。 Changes
Sequence Diagram(s)(无) Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
诗歌
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
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. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1219 +/- ##
=======================================
Coverage 99.44% 99.44%
=======================================
Files 31 31
Lines 1251 1256 +5
Branches 454 437 -17
=======================================
+ Hits 1244 1249 +5
Misses 7 7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@tests/Tags.test.tsx`:
- Around line 150-171: The test currently only asserts handleSelect call count
which can hide semantic failures; update the test case for the Select in tags
mode to also assert the onSelect payload to ensure the highlighted option was
actually selected. After the Enter key sequence (where handleSelect jest.fn() is
invoked), add an assertion checking handleSelect was called with the expected
selected value/option (e.g., matching value 'opt1' or the option object for the
first highlighted item) so the test verifies both occurrence and correctness for
onSelect.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 05edff92-9401-4ef5-9263-389b3c2d5486
📒 Files selected for processing (2)
src/SelectInput/Input.tsxtests/Tags.test.tsx
|
|
||
| // Handle Enter key submission - referencing Selector implementation | ||
| if (key === 'Enter' && mode === 'tags' && !compositionStatusRef.current && onSearchSubmit) { | ||
| if ( |
There was a problem hiding this comment.
是不是应该检测一下是否有内容再决定?按理说这个 Input 的优先级会更高,只有没有内容的时候再认为是 option 响应会比较好~

问题
在
mode="tags"下,用户输入(如 "da")后按回车选择下拉中的选项(如 "Dacryoadenitis")时,onSelect会触发两次:关联缺陷
fix ant-design/ant-design#57285
原因
语义化重构(#1166)之后,
SelectInput/Input.tsx里在 tags 模式下按 Enter 会无条件调用onSearchSubmit。旧版 Selector 只在菜单关闭时(!open)才调用,重构时漏掉了这个条件,造成回归。修改
仅在下拉关闭(
!open)时调用onSearchSubmit。下拉打开时由 OptionList 处理 Enter 选中当前高亮项(与 BaseSelect 注释中的设计一致)。变更说明
!open判断再调用onSearchSubmit。验证
Summary by CodeRabbit
发布说明
Bug Fixes
Tests