Conversation
Pass rawOpen through context and use it in MultipleContent to prevent search value from being cleared when emptyListContent blocks the dropdown from opening. Also adds test coverage for the multiple mode case. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Walkthrough将 BaseSelectContext 中暴露 Changes
Sequence Diagram(s)sequenceDiagram
participant User as User
participant MC as MultipleContent
participant BSC as BaseSelectContext
User->>MC: 输入字符(typing)
MC->>BSC: 读取当前 open 状态(rawOpen)
BSC-->>MC: 返回 rawOpen 值
alt rawOpen == true
MC->>MC: 保留搜索内容(不清空)
else rawOpen == false
MC->>MC: 清空搜索内容
end
MC-->>User: 更新输入框显示 / onSearch 回调
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
诗歌
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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 |
Summary of ChangesHello @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 addresses a bug in the 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
Activity
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
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1202 +/- ##
=======================================
Coverage 99.43% 99.43%
=======================================
Files 31 31
Lines 1230 1230
Branches 419 419
=======================================
Hits 1223 1223
Misses 7 7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Code Review
This pull request correctly fixes an issue where the search value was being cleared in multiple mode when notFoundContent is null and no options match. The changes are well-targeted, passing rawOpen through the context and using it to decide whether to clear the search input. The added test case for multiple mode effectively covers this fix. I have one suggestion to refactor the new tests to reduce code duplication and improve maintainability.
| describe('should allow typing when notFoundContent is null and no options match', () => { | ||
| it('single', () => { | ||
| const onSearch = jest.fn(); | ||
| const { container } = render( | ||
| <Select showSearch notFoundContent={null} onSearch={onSearch}> | ||
| <Option value="jack">Jack</Option> | ||
| <Option value="lucy">Lucy</Option> | ||
| </Select>, | ||
| ); | ||
|
|
||
| const input = container.querySelector('input'); | ||
| const input = container.querySelector('input'); | ||
|
|
||
| // Type 'j' - should match 'Jack' | ||
| fireEvent.change(input, { target: { value: 'j' } }); | ||
| expect(onSearch).toHaveBeenLastCalledWith('j'); | ||
| expect(input.value).toBe('j'); | ||
| expect(container.querySelectorAll('.rc-select-item-option')).toHaveLength(1); | ||
|
|
||
| // Type 'j' - should match 'Jack' | ||
| fireEvent.change(input, { target: { value: 'j' } }); | ||
| expect(onSearch).toHaveBeenLastCalledWith('j'); | ||
| expect(input.value).toBe('j'); | ||
| expect(container.querySelectorAll('.rc-select-item-option')).toHaveLength(1); | ||
|
|
||
| // Type 'x' - no match, but input should still work | ||
| fireEvent.change(input, { target: { value: 'x' } }); | ||
| expect(onSearch).toHaveBeenLastCalledWith('x'); | ||
| expect(input.value).toBe('x'); | ||
|
|
||
| // Type more characters - should continue working | ||
| fireEvent.change(input, { target: { value: 'xyz' } }); | ||
| expect(onSearch).toHaveBeenLastCalledWith('xyz'); | ||
| expect(input.value).toBe('xyz'); | ||
| // Type 'x' - no match, but input should still work | ||
| fireEvent.change(input, { target: { value: 'x' } }); | ||
| expect(onSearch).toHaveBeenLastCalledWith('x'); | ||
| expect(input.value).toBe('x'); | ||
|
|
||
| // Type more characters - should continue working | ||
| fireEvent.change(input, { target: { value: 'xyz' } }); | ||
| expect(onSearch).toHaveBeenLastCalledWith('xyz'); | ||
| expect(input.value).toBe('xyz'); | ||
| }); | ||
|
|
||
| it('multiple', () => { | ||
| const onSearch = jest.fn(); | ||
| const { container } = render( | ||
| <Select mode="multiple" showSearch notFoundContent={null} onSearch={onSearch}> | ||
| <Option value="jack">Jack</Option> | ||
| <Option value="lucy">Lucy</Option> | ||
| </Select>, | ||
| ); | ||
|
|
||
| const input = container.querySelector('input'); | ||
|
|
||
| // Type 'j' - should match 'Jack' | ||
| fireEvent.change(input, { target: { value: 'j' } }); | ||
| expect(onSearch).toHaveBeenLastCalledWith('j'); | ||
| expect(input.value).toBe('j'); | ||
| expect(container.querySelectorAll('.rc-select-item-option')).toHaveLength(1); | ||
|
|
||
| // Type 'x' - no match, but input should still work | ||
| fireEvent.change(input, { target: { value: 'x' } }); | ||
| expect(onSearch).toHaveBeenLastCalledWith('x'); | ||
| expect(input.value).toBe('x'); | ||
|
|
||
| // Type more characters - should continue working | ||
| fireEvent.change(input, { target: { value: 'xyz' } }); | ||
| expect(onSearch).toHaveBeenLastCalledWith('xyz'); | ||
| expect(input.value).toBe('xyz'); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
The tests for 'single' and 'multiple' modes are nearly identical. To improve maintainability and reduce code duplication, you could refactor them using it.each to run the same test logic for both modes.
describe('should allow typing when notFoundContent is null and no options match', () => {
it.each(['single', 'multiple'] as const)('%s', (mode) => {
const onSearch = jest.fn();
const { container } = render(
<Select
mode={mode === 'single' ? undefined : mode}
showSearch
notFoundContent={null}
onSearch={onSearch}
>
<Option value="jack">Jack</Option>
<Option value="lucy">Lucy</Option>
</Select>,
);
const input = container.querySelector('input');
// Type 'j' - should match 'Jack'
fireEvent.change(input, { target: { value: 'j' } });
expect(onSearch).toHaveBeenLastCalledWith('j');
expect(input.value).toBe('j');
expect(container.querySelectorAll('.rc-select-item-option')).toHaveLength(1);
// Type 'x' - no match, but input should still work
fireEvent.change(input, { target: { value: 'x' } });
expect(onSearch).toHaveBeenLastCalledWith('x');
expect(input.value).toBe('x');
// Type more characters - should continue working
fireEvent.change(input, { target: { value: 'xyz' } });
expect(onSearch).toHaveBeenLastCalledWith('xyz');
expect(input.value).toBe('xyz');
});
});
Combine single and multiple mode tests into a parametrized test using it.each for better maintainability. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Pass rawOpen through context and use it in MultipleContent to prevent search value from being cleared when emptyListContent blocks the dropdown from opening. Also adds test coverage for the multiple mode case.
fix ant-design/ant-design#56735
Summary by CodeRabbit
发行说明
Bug 修复
测试