fix: avoid selecting disabled options via keyboard in Mentions#308
fix: avoid selecting disabled options via keyboard in Mentions#308zombieJ merged 3 commits intoreact-component:masterfrom
Conversation
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! This pull request significantly improves the user experience and accessibility of the Mentions component by addressing several issues related to disabled options. Previously, users could inadvertently select or highlight disabled options via keyboard navigation, leading to inconsistent and unexpected behavior. The changes introduce robust logic to ensure that all keyboard and mouse interactions correctly respect the disabled state of options, making the component more predictable and user-friendly, and aligning its behavior with common UI patterns. 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
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Walkthrough该变更在 DropdownMenu 与 Mentions 中引入对禁用选项的护卫与跳过逻辑,确保在鼠标悬停、键盘导航和回车选择时不会激活或选择被禁用的项,并为 Mentions 添加相关测试覆盖。 Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant DropdownMenu as DropdownMenu
participant Mentions
participant Options as OptionsList
User->>DropdownMenu: 鼠标悬停某项
DropdownMenu->>DropdownMenu: 检查项是否禁用
alt 项目已禁用
DropdownMenu->>DropdownMenu: 不调用 setActiveIndex
else 项目已启用
DropdownMenu->>DropdownMenu: 调用 setActiveIndex(index)
end
User->>Mentions: 按下 Arrow Up/Down
Mentions->>Options: 请求下一个索引
Mentions->>Mentions: 调用 getEnabledActiveIndex(offset)(跳过禁用项)
Mentions->>Mentions: 更新 activeIndex
User->>Mentions: 按下 Enter
Mentions->>Mentions: 校验 current activeIndex 是否存在且非禁用
alt 无效或为禁用项
Mentions->>Mentions: 使用 getEnabledActiveIndex(0) 选择首个可用项
end
Mentions->>Mentions: 调用 selectOption 并提交选择
Estimated code review effort🎯 3 (中等) | ⏱️ ~20 minutes Possibly related issues
Suggested reviewers
Poem
🚥 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 |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #308 +/- ##
==========================================
- Coverage 98.51% 98.33% -0.18%
==========================================
Files 8 8
Lines 270 301 +31
Branches 65 79 +14
==========================================
+ Hits 266 296 +30
- Misses 4 5 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…re safe handling when options list shrinks
问题
disabled,按 Enter 仍会选中它并插入到文本中;disabled选项上,导致 “高亮在灰项 + Enter 插入/无响应” 的不一致体验;修复方案
src/Mentions.tsx中新增getEnabledActiveIndex,用于从当前索引出发按方向查找下一个非disabled的选项。activeIndex校正为首个可用项(全部 disabled 时为-1)。getEnabledActiveIndex跳过所有disabled选项。disabled,尝试 fallback 到第一个可用项;若全部disabled,仅结束测量,不修改文本。selectOption中对disabled做早返回,避免任何路径下选中禁用项。DropdownMenu中,鼠标 hoverdisabled项时不再改变activeIndex,与 rc-select 行为一致。测试
disabled时,Enter 应选中下一个可用项;disabled时,Enter 不修改文本;disabled选项。npm test通过。fix: ant-design/ant-design#56934
Summary by CodeRabbit
Bug Fixes
Tests