Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: onSearch be call onBlur #1085

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

su-muzhi
Copy link

@su-muzhi su-muzhi commented Nov 12, 2024

fix ant-design/ant-design#50642

Summary by CodeRabbit

  • 新功能

    • 改进了BaseSelect组件的搜索功能和下拉菜单可见性,提供更直观的用户体验。
  • 测试

    • BaseSelect组件新增了测试用例,增强了对搜索输入和焦点事件的覆盖。
    • 更新了Select组件的测试,确保其在各种场景下的功能和行为正常,包括下拉菜单的打开和关闭、焦点和失去焦点事件的处理。

Copy link

vercel bot commented Nov 12, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
select ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 14, 2024 2:54am

Copy link
Contributor

coderabbitai bot commented Nov 12, 2024

Walkthrough

本次变更主要涉及BaseSelect组件的搜索功能和下拉菜单可见性的处理。onInternalSearch函数进行了更新,以便在下拉菜单未打开且模式不是'combobox'时,将搜索事件的来源从'输入'或'效果'更改为'失去焦点'。此外,管理下拉菜单打开状态的逻辑也得到了优化,确保在下拉菜单禁用或列表为空时不会保持打开状态。同时,onInternalKeyDown函数的修改防止在非组合框模式下按下回车键时提交表单。

Changes

文件路径 变更摘要
src/BaseSelect/index.tsx 更新onInternalSearch函数和下拉菜单可见性逻辑;修改onSearch方法签名。
tests/BaseSelect.test.tsx 添加新的测试用例,验证onContainerBlur参数在不同模式下的行为。
tests/Select.test.tsx 增强对焦点和失去焦点事件的测试;验证下拉菜单的行为及其可访问性。

Assessment against linked issues

Objective Addressed Explanation
当mode为multiple时,失去焦点后不请求sug接口的一致性 ( #50642 )

Possibly related PRs

Suggested reviewers

  • afc163

兔子欢快地跳跃,
搜索功能更流畅,
下拉菜单不再开,
用户体验真美好!
一起欢庆新变化,
让我们继续加油吧! 🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

tests/Select.test.tsx

Oops! Something went wrong! :(

ESLint: 8.57.1

Error: Cannot read config file: /.eslintrc.js
Error: Cannot find module '@umijs/fabric/dist/eslint'
Require stack:

  • /.eslintrc.js
  • /node_modules/@eslint/eslintrc/dist/eslintrc.cjs
  • /node_modules/eslint/lib/cli-engine/cli-engine.js
  • /node_modules/eslint/lib/eslint/eslint.js
  • /node_modules/eslint/lib/eslint/index.js
  • /node_modules/eslint/lib/cli.js
  • /node_modules/eslint/bin/eslint.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1248:15)
    at Module._load (node:internal/modules/cjs/loader:1074:27)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:217:24)
    at Module.require (node:internal/modules/cjs/loader:1339:12)
    at require (node:internal/modules/helpers:135:16)
    at Object. (/.eslintrc.js:1:14)
    at Module._compile (node:internal/modules/cjs/loader:1546:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1691:10)
    at Module.load (node:internal/modules/cjs/loader:1317:32)

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c4fd947 and 53fef45.

📒 Files selected for processing (1)
  • tests/Select.test.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/Select.test.tsx

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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: 2

🧹 Outside diff range and nitpick comments (1)
tests/BaseSelect.test.tsx (1)

128-149: 建议完善测试用例的覆盖范围

当前测试用例存在以下需要改进的地方:

  1. 测试名称应该反映showSearch={true}的设置
  2. 缺少对初始searchValue="1"的验证
  3. 建议添加showSearch={false}的场景测试

建议修改如下:

-  it('mode with null, onContainerBlur params is blur', () => {
+  it('mode为null且showSearch为true时,onContainerBlur触发onSearch', () => {
     const onSearch = jest.fn();
     const { container } = render(
       // ... existing code ...
     );
+    // 验证初始值
+    expect(container.querySelector('input').value).toBe('1');
     // ... remaining code ...
   });

+  it('mode为null且showSearch为false时,onContainerBlur不触发onSearch', () => {
+    // 添加showSearch=false的测试用例
+  });
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 27ac66f and 567a898.

📒 Files selected for processing (3)
  • src/BaseSelect/index.tsx (1 hunks)
  • tests/BaseSelect.test.tsx (1 hunks)
  • tests/Select.test.tsx (1 hunks)
🔇 Additional comments (3)
tests/BaseSelect.test.tsx (2)

127-127: 测试结构清晰明确!

测试套件的命名准确反映了其测试目的,结构符合最佳实践。


127-174: 建议增加测试用例以确保完整的行为覆盖

当前的测试用例集没有完全覆盖PR的目标场景。为确保修复的完整性,建议添加以下测试场景:

  1. 单选模式下的行为测试,以便与多选模式进行对比
  2. 验证重新获得焦点时是否会触发新的搜索请求
  3. 测试空值和特殊字符的搜索行为
src/BaseSelect/index.tsx (1)

438-438: 搜索事件源的逻辑修改看起来符合预期

这个改动通过在 mergedShowSearch 为 true 时将搜索事件源从 'typing' 或 'effect' 更改为 'blur',解决了重新获得焦点时不必要的建议请求问题。这与 PR 的目标一致。

运行以下脚本验证此更改是否正确处理了所有搜索事件源:

✅ Verification successful

Let me gather more context about the search event handling to ensure a comprehensive verification.


Let me try one more verification to check the component's search-related logic:


让我检查一下相关的测试文件以确保这个改动的行为是否符合预期:


搜索事件源的修改已得到验证,实现符合预期

根据代码分析和测试用例验证,这个改动是正确的:

  • 在输入时触发 source: 'typing'
  • 在失焦时触发 source: 'blur'
  • 在其他情况下触发 source: 'effect'source: 'submit'

这个修改完全符合 PR 的目标,能够正确处理重新获得焦点时的搜索行为,避免不必要的建议请求。测试用例也验证了这些行为。

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 检查代码库中是否存在其他使用 onSearch 的地方
ast-grep --pattern 'onSearch($_, { source: $_ })'

Length of output: 571


Script:

#!/bin/bash
# 检查 onSearch 的定义和类型
ast-grep --pattern 'onSearch?: $_'

# 检查相关的测试用例
rg "onSearch.*source" -A 3 -B 3 "test|spec|__tests__"

Length of output: 152


Script:

#!/bin/bash
# 检查组件中与搜索相关的状态和处理逻辑
rg "onSearch|showSearch|searchValue" -A 2 -B 2 src/BaseSelect/index.tsx

# 查找测试文件
fd "test|spec" -e tsx -e ts

Length of output: 3571


Script:

#!/bin/bash
# 检查测试文件中与搜索事件源相关的测试用例
rg "onSearch.*source|showSearch.*blur" -A 3 -B 3 tests/

# 特别关注与 blur 事件相关的测试
rg "test.*blur" -A 5 -B 2 tests/

Length of output: 1397

tests/BaseSelect.test.tsx Outdated Show resolved Hide resolved
tests/Select.test.tsx Outdated Show resolved Hide resolved
src/BaseSelect/index.tsx Outdated Show resolved Hide resolved
Copy link

codecov bot commented Nov 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.38%. Comparing base (27ac66f) to head (53fef45).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1085      +/-   ##
==========================================
+ Coverage   98.24%   98.38%   +0.13%     
==========================================
  Files          39       39              
  Lines        1483     1483              
  Branches      441      447       +6     
==========================================
+ Hits         1457     1459       +2     
+ Misses         26       24       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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】select组件的showSearch功能在mode是否为multiple时下拉选项表现不一致
3 participants