-
-
Notifications
You must be signed in to change notification settings - Fork 478
fix: Select dropdown should scroll to the option with the closest prefix to the searched value. #1146
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: Select dropdown should scroll to the option with the closest prefix to the searched value. #1146
Conversation
…fix to the searched value.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Walkthrough本次更改调整了在单选模式下打开选项列表时,确定活动选项的逻辑。当存在搜索输入时,优先根据搜索字符串前缀匹配选项值,否则仍按原有方式精确匹配选项值。 Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant OptionList
User->>OptionList: 打开选项列表(单选模式)
OptionList->>OptionList: 检查是否有搜索输入
alt 有搜索输入
OptionList->>OptionList: 查找第一个以搜索值为前缀的选项
else 没有搜索输入
OptionList->>OptionList: 精确匹配已选值
end
OptionList->>OptionList: 设置活动选项并滚动到视图
Suggested reviewers
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
src/OptionList.tsxOops! Something went wrong! :( ESLint: 8.57.1 Error: Cannot read config file: /.eslintrc.js
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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, );
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. 🚀 New features to boost your workflow:
|
…fix to the searched value. (#1146)
…fix to the searched value. (#1146)
Should fix : ant-design/ant-design#53752
Summary by CodeRabbit