Skip to content

Conversation

@claytonlin1110
Copy link
Contributor

@claytonlin1110 claytonlin1110 commented Feb 11, 2026

🔗 Related Issues

#56939
#56943

Background & Solution

Background

Due to this PR, space bar is not typed in opened select box.

Solution

Open select box by space only when it's not opened yet so that user can still type a space in opened box.

Summary by CodeRabbit

  • Bug 修复
    • 优化了 Select 组件在按 Enter/Space 时的行为:仅在下拉即将打开(当前为关闭)时阻止默认提交,按 Enter/Space 可在关闭时打开下拉;当下拉已打开时,按键不再无谓阻止默认行为,交互更符合预期。

@vercel
Copy link

vercel bot commented Feb 11, 2026

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

A member of the Team first needs to authorize it.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @claytonlin1110, 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 refines the keyboard interaction within the BaseSelect component by adjusting the behavior of the 'Enter' key. The change ensures that the default form submission is prevented only when the 'Enter' key is used to initially open the select box, providing more precise control over event handling in different states of the component.

Highlights

  • Enter Key Event Handling: The logic for preventing default form submission when the 'Enter' key is pressed in the BaseSelect component has been refined. The event.preventDefault() call is now executed only when the select box is not already open, ensuring that form submission is prevented specifically when 'Enter' is used to trigger the opening of the component.
  • Discrepancy Note: While the pull request title and description indicate a fix for the spacebar input in an opened select box, the provided patch exclusively shows changes related to the 'Enter' key's behavior. This summary reflects the changes observed in the provided code diff for the 'Enter' key.

🧠 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
  • src/BaseSelect/index.tsx
    • Refactored 'Enter' key event handling to conditionally prevent default behavior.
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.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 11, 2026

Walkthrough

此更改调整了 BaseSelect 组件中 Enter/Space 键的键盘处理:仅在下拉尚未打开(mergedOpen 为 false)时阻止默认提交,其他行为(按键触发展开)保持不变。

Changes

Cohort / File(s) Summary
BaseSelect 键盘事件处理
src/BaseSelect/index.tsx
修改 Enter/Space 的 keydown 处理:将 preventDefault 限定到 mergedOpen 为 false 的分支,避免在下拉已打开时无谓阻止默认提交。

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 分钟

Possibly related PRs

Suggested reviewers

  • yoyo837
  • zombieJ

诗句

🐰 轻敲键盘不慌忙,
Enter 只在闭合时挡,
打开时让流程跑一跑,
小兔点点微笑忙,
选择更顺畅,心情好。 🎋

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了PR的主要改动:启用空格键在打开状态下被键入,这正是代码改动的核心目的。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

No actionable comments were generated in the recent review. 🎉


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.

@claytonlin1110 claytonlin1110 force-pushed the fix/spacebar-enable-opened branch from a2df78d to f366628 Compare February 11, 2026 10:57
@codecov
Copy link

codecov bot commented Feb 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.43%. Comparing base (87e9941) to head (f366628).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1204   +/-   ##
=======================================
  Coverage   99.43%   99.43%           
=======================================
  Files          31       31           
  Lines        1230     1230           
  Branches      441      441           
=======================================
  Hits         1223     1223           
  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.

Copy link
Contributor

@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

The pull request aims to address an issue where the spacebar cannot be typed in an opened select box. However, the provided code changes in src/BaseSelect/index.tsx modify the behavior of the Enter key. The change to the Enter key's event.preventDefault() logic appears to introduce a regression: it now only prevents default form submission when the select dropdown is not already open. This means if a user presses Enter while the dropdown is open (e.g., to confirm a selection), the default browser behavior, such as form submission, might occur instead of the intended action within the select component. Please clarify if the intention was to modify the Enter key or if the spacebar issue needs to be addressed in a different part of the codebase, and consider reverting the Enter key change to maintain existing functionality.

Comment on lines 469 to 473
const isSpaceKey = key === ' ';

// Enter or Space opens dropdown (ARIA combobox: spacebar should open)
if (isEnterKey || isSpaceKey) {
// Do not submit form when type in the input; prevent Space from scrolling page
if (mode !== 'combobox') {
event.preventDefault();
}

if (isEnterKey || isSpaceKey) {
// We only manage open state here, close logic should handle by list component
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The event.preventDefault() call for the Enter key has been moved inside the if (!mergedOpen) block. This means that when the select dropdown is already open (mergedOpen is true), pressing the Enter key will no longer prevent the default browser behavior (e.g., form submission) if mode !== 'combobox'. This is a regression, as Enter key typically confirms selection and prevents form submission when the dropdown is active. The original placement ensured event.preventDefault() was always called for Enter key in non-combobox modes.

      // Do not submit form when type in the input
      if (mode !== 'combobox') {
        event.preventDefault();
      }
      // We only manage open state here, close logic should handle by list component
      if (!mergedOpen) {
        triggerOpen(true);
      }

@claytonlin1110
Copy link
Contributor Author

@afc163 Please review

@QDyanbing
Copy link

QDyanbing commented Feb 11, 2026

感觉移动 event.preventDefault() 的位置影响有点大
https://github.com/react-component/select/pull/1203/changes 这样是否可行

@claytonlin1110
Copy link
Contributor Author

I think moving the position of event.preventDefault() (so it runs only when !mergedOpen) is the right fix. PR #1203 is feasible for typing space in the input but not sufficient for space-to-open without scroll; keeping the “by dropdown state” condition is the better approach.

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