Skip to content

Conversation

@justanotheranonymoususer
Copy link
Contributor

@justanotheranonymoususer justanotheranonymoususer commented Dec 26, 2025

Right now, if focused, it's being opened on hotkeys like Ctrl+F to search, Ctrl+S to save page, etc.

Summary by CodeRabbit

  • Bug Fixes
    • 优化了 Select 的键盘交互:仅在按下指定打开键且未同时按任何修饰键(Ctrl、Alt、Meta)时触发下拉,避免修饰键组合误触发,提升操作精确性与可预测性。
  • Tests
    • 增加覆盖该行为的测试用例,确保带修饰键的快捷键不会意外打开下拉。
  • Chores
    • 测试工具事件触发支持额外键盘事件选项,便于更精确的按键模拟。

✏️ Tip: You can customize this high-level summary in your review settings.

@vercel
Copy link

vercel bot commented Dec 26, 2025

@justanotheranonymoususer is attempting to deploy a commit to the React Component Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 26, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

该 PR 修改了 Select 组件的键盘交互与测试:限制只有在按下有效 open-key 且未同时按下任何修饰键(Ctrl、Alt、Meta)时才打开下拉,同时新增相应单元测试并扩展测试工具的 keyDown 选项参数以支持传入修饰键信息。

Changes

Cohort / File(s) 变更摘要
键盘事件处理
src/SelectInput/index.tsx
在内部 input 的 keydown 处理器中新增修饰键检查:只有在检测到有效的 open-key 且未按下 Ctrl/Alt/Meta 时,才触发打开下拉菜单的逻辑。注意边界条件与 key 判定分支。
测试:行为验证
tests/Select.test.tsx
新增用例,验证带有修饰键(Ctrl/Alt/Meta)的浏览器快捷键不会打开 Select,而普通按键仍会打开。
测试工具:事件创建
tests/utils/common.ts
更新 keyDown 函数签名以接受可选 options?: Partial<KeyboardEvent>,并在创建事件时合并该选项以支持传入修饰键等事件属性。注意确保调用方传参和现有测试兼容。

Sequence Diagram(s)

(无;变更为单文件与测试相关的小范围键盘事件判断与测试工具扩展,不满足生成序列图的条件。)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • afc163
  • zombieJ

Poem

🐰 我在键盘边踱步,轻嗅风中键位声,
修饰键若来捣乱,下拉就别登场,
普通按键敲一敲,菜单悄然现身听,
小兔欢跳庆一曲,测试绿灯齐声鸣 🎉

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题清晰准确地总结了主要变更:防止浏览器热键(如Ctrl+F、Ctrl+S)打开Select组件,与代码变更完全相关。
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 84596b0 and 0536698.

📒 Files selected for processing (2)
  • tests/Select.test.tsx
  • tests/utils/common.ts
🧰 Additional context used
🧬 Code graph analysis (1)
tests/Select.test.tsx (1)
tests/utils/common.ts (2)
  • keyDown (113-126)
  • expectOpen (4-20)
🔇 Additional comments (2)
tests/utils/common.ts (1)

113-118: LGTM!测试工具函数扩展合理

keyDown 函数的扩展设计良好,通过可选的 options 参数支持传入修饰键属性,实现向后兼容。这使得测试能够模拟带修饰键的键盘事件(如 Ctrl+F),符合 PR 的目标。

tests/Select.test.tsx (1)

1011-1039: 测试用例正确,生产代码实现无误

测试有效地验证了修饰键(Ctrl、Alt、Meta)与浏览器快捷键组合时不会打开下拉菜单的功能。生产代码在 src/SelectInput/index.tsx 第 150 行的修饰键检查 const isModifier = event.ctrlKey || event.altKey || event.metaKey; 与测试期望完全对应,确保只有不带修饰键的按键才能触发下拉菜单打开。keyDown 辅助函数正确支持修饰键参数传递,KeyCode 常量来自外部库且正确使用。无需改动。


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

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link

Summary of Changes

Hello @justanotheranonymoususer, 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 an issue where the SelectInput component's dropdown would open unexpectedly when users pressed common browser hotkeys while the component was focused. The change improves the user experience by ensuring the select input only responds to intended key presses, thereby avoiding conflicts with native browser functionality and enhancing overall usability.

Highlights

  • Prevent Unintended Dropdown Opening: The SelectInput component has been updated to prevent its dropdown from opening when browser hotkeys (e.g., Ctrl+F, Ctrl+S) are pressed. This is achieved by adding checks for modifier keys (Ctrl, Alt, Meta) to the key press validation logic.

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

Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly prevents the select dropdown from opening when browser hotkeys like Ctrl+F are used. The change is a good fix for the described issue. I've added a comment with a suggestion to slightly improve readability and to add a test case to prevent future regressions of this behavior.

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 (2)
src/SelectInput/index.tsx (2)

150-150: 可选:考虑是否需要检查 shiftKey。

当前实现未检查 event.shiftKey,这可能是有意为之(例如 Shift+字母用于输入大写字母时应该打开下拉菜单)。但如果某些 Shift 组合键(如 Shift+方向键)不应触发打开,可以考虑添加更精细的控制。

如需添加,可参考:

-if (!event.ctrlKey && !event.altKey && !event.metaKey && isValidateOpenKey(which)) {
+if (!event.ctrlKey && !event.altKey && !event.metaKey && !event.shiftKey && isValidateOpenKey(which)) {

注意:这可能会影响正常的 Shift+字母输入行为,请谨慎评估是否需要此更改。


150-152: 修复方案有效,正确防止浏览器快捷键触发下拉菜单打开。

添加修饰键检查(!event.ctrlKey && !event.altKey && !event.metaKey)可以防止 Ctrl+F、Ctrl+S 等浏览器快捷键触发下拉菜单打开。虽然 isValidateOpenKey() 已排除单独的修饰键按码,但它无法阻止修饰键与字母组合(如 Ctrl+F)的情况,因为字母键本身会通过验证。新增的事件修饰符属性检查弥补了这一空隙,实现简洁且符合预期。

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 73d9975 and 5099c58.

📒 Files selected for processing (1)
  • src/SelectInput/index.tsx
🧰 Additional context used
🧬 Code graph analysis (1)
src/SelectInput/index.tsx (1)
src/utils/keyUtil.ts (1)
  • isValidateOpenKey (4-45)

@codecov
Copy link

codecov bot commented Dec 26, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.42%. Comparing base (73d9975) to head (0536698).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1191   +/-   ##
=======================================
  Coverage   99.42%   99.42%           
=======================================
  Files          31       31           
  Lines        1216     1217    +1     
  Branches      433      434    +1     
=======================================
+ Hits         1209     1210    +1     
  Misses          7        7           

☔ 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 6c4742e into react-component:master Dec 26, 2025
9 of 10 checks passed
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.

2 participants