Skip to content

Conversation

js0753
Copy link
Contributor

@js0753 js0753 commented May 7, 2025

Should fix : ant-design/ant-design#53752

Summary by CodeRabbit

  • 优化
    • 改进了单选模式下选项列表打开时的选中项定位逻辑,支持根据当前搜索输入优先定位到首个匹配项,提升搜索和选择体验。

Copy link

vercel bot commented May 7, 2025

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 May 7, 2025 9:10am

Copy link
Contributor

coderabbitai bot commented May 7, 2025

Walkthrough

本次更改调整了在单选模式下打开选项列表时,确定活动选项的逻辑。当存在搜索输入时,优先根据搜索字符串前缀匹配选项值,否则仍按原有方式精确匹配选项值。

Changes

文件 变更摘要
src/OptionList.tsx 修改了选项激活逻辑:在有搜索值时,优先用前缀匹配选项,否则精确匹配。

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant OptionList

    User->>OptionList: 打开选项列表(单选模式)
    OptionList->>OptionList: 检查是否有搜索输入
    alt 有搜索输入
        OptionList->>OptionList: 查找第一个以搜索值为前缀的选项
    else 没有搜索输入
        OptionList->>OptionList: 精确匹配已选值
    end
    OptionList->>OptionList: 设置活动选项并滚动到视图
Loading

Suggested reviewers

  • zombieJ

Poem

小兔子跳进代码林,
搜索前缀巧更新。
单选列表更聪明,
活动选项随心寻。
一行逻辑新春意,
用户体验更贴心。

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.

src/OptionList.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/.pnpm/@eslint[email protected]/node_modules/@eslint/eslintrc/dist/eslintrc.cjs
  • /node_modules/.pnpm/[email protected]/node_modules/eslint/lib/cli-engine/cli-engine.js
  • /node_modules/.pnpm/[email protected]/node_modules/eslint/lib/eslint/eslint.js
  • /node_modules/.pnpm/[email protected]/node_modules/eslint/lib/eslint/index.js
  • /node_modules/.pnpm/[email protected]/node_modules/eslint/lib/cli.js
  • /node_modules/.pnpm/[email protected]/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)
✨ Finishing Touches
  • 📝 Generate Docstrings

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

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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: 0

🧹 Nitpick comments (1)
src/OptionList.tsx (1)

160-163: 良好的增强功能,但考虑使用不区分大小写的匹配

当用户在选择框中输入搜索内容时,此更改使下拉列表滚动到以搜索值开头的第一个选项,而不是仅突出显示当前已选值,这极大地提升了用户体验。然而,startsWith方法是区分大小写的,这可能会导致用户在输入大小写不完全匹配的搜索词时无法找到预期的选项。

考虑使用不区分大小写的匹配以提升用户体验:

const index = memoFlattenOptions.findIndex(({ data }) =>
-  searchValue ? String(data.value).startsWith(searchValue) : data.value === value,
+  searchValue 
+    ? String(data.value).toLowerCase().startsWith(searchValue.toLowerCase()) 
+    : data.value === value,
);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 27a225e and 47985eb.

📒 Files selected for processing (1)
  • src/OptionList.tsx (1 hunks)

Copy link

codecov bot commented May 7, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.26%. Comparing base (27a225e) to head (47985eb).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1146   +/-   ##
=======================================
  Coverage   98.26%   98.26%           
=======================================
  Files          39       39           
  Lines        1500     1501    +1     
  Branches      425      426    +1     
=======================================
+ Hits         1474     1475    +1     
  Misses         26       26           

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@afc163 afc163 merged commit c00c681 into react-component:master May 7, 2025
11 checks passed
afc163 pushed a commit that referenced this pull request May 7, 2025
afc163 pushed a commit that referenced this pull request May 7, 2025
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 dropdown on search doesn't scroll to the correct options
2 participants