Skip to content

feat: add disableAutoScroll prop to control auto-scrolling behavior in the select component#1197

Closed
aeifn wants to merge 6 commits into
react-component:masterfrom
aeifn:master
Closed

feat: add disableAutoScroll prop to control auto-scrolling behavior in the select component#1197
aeifn wants to merge 6 commits into
react-component:masterfrom
aeifn:master

Conversation

@aeifn

@aeifn aeifn commented Jan 30, 2026

Copy link
Copy Markdown

The disableAutoScroll prop provides users with control over the automatic scrolling behavior in single-select
mode. By default, the Select component automatically scrolls to the selected option when the dropdown opens,
which can be disruptive in certain UX scenarios where users want to maintain their current scroll position or
handle scrolling manually.

This addition allows developers to disable the auto-scroll behavior while preserving all other functionality.

Summary by CodeRabbit

  • 新增功能

    • 为 Select 组件添加公有布尔属性 disableAutoScroll,可用于禁用选中单项时的自动滚动行为(默认 false)。
  • 文档

    • 更新组件文档与 API 表,新增 disableAutoScroll 属性说明及默认值。

@vercel

vercel Bot commented Jan 30, 2026

Copy link
Copy Markdown

@aeifn 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
Copy Markdown
Contributor

Summary of Changes

Hello @aeifn, 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 introduces a new disableAutoScroll prop to the Select component, providing developers with granular control over the automatic scrolling behavior that typically occurs when a dropdown opens in single-select mode. This enhancement aims to improve user experience by preventing potentially disruptive auto-scrolling, allowing for scenarios where maintaining the current scroll position or manual scrolling is preferred, without affecting other functionalities.

Highlights

  • New Prop Introduction: A new disableAutoScroll boolean prop has been added to the Select component, allowing developers to control the automatic scrolling behavior of the dropdown.
  • Conditional Auto-Scrolling: The internal logic within the OptionList component has been updated to conditionally disable auto-scrolling based on the value of the new disableAutoScroll prop, specifically in single-select mode.
  • Prop Propagation: The disableAutoScroll prop is now correctly passed from the Select component to its child OptionList component and has been added to the SelectContextProps interface.
  • Documentation Update: The README.md file has been updated to include the new disableAutoScroll prop in the component's API documentation, specifying its type and default value.

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

@coderabbitai

coderabbitai Bot commented Jan 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 297f315d-3f7b-4671-8543-e43e85d3eb8f

📥 Commits

Reviewing files that changed from the base of the PR and between d368018 and 3f8af78.

📒 Files selected for processing (3)
  • README.md
  • src/OptionList.tsx
  • src/Select.tsx

Walkthrough

为 Select 增加公开布尔属性 disableAutoScroll(默认 false),将其加入 SelectContext,并在 OptionList 中消费该标志以在单选、仅有 1 项时控制是否自动滚动;同时在 README 的 API 表中添加该属性说明。

Changes

新增 disableAutoScroll(文档 + Context + 组件)

Layer / File(s) Summary
公开 prop 与 Context 声明
src/Select.tsx, src/SelectContext.ts
SelectPropsSelectContextProps 中新增可选布尔属性 disableAutoScroll?: boolean,并在 Select 组件中解构该 prop 准备透传到 context(useMemo 依赖已更新)。
OptionList 自动滚动判断
src/OptionList.tsx
从 context 读取 disableAutoScroll;在单选且仅剩 1 个选项时,自动滚动条件新增 !disableAutoScroll 约束;对应的 useEffect 依赖数组包含 disableAutoScroll
文档
README.md
在 Select 组件的 Props/API 表中添加 disableAutoScroll 的说明、适用范围(仅单选)与默认值。

Sequence Diagram(s)

sequenceDiagram
    participant App as 应用 (传入 prop)
    participant Select as Select 组件
    participant Context as SelectContext
    participant OptionList as OptionList 组件
    App->>Select: 传入 disableAutoScroll (true/false)
    Select->>Context: 将 disableAutoScroll 写入 context
    OptionList->>Context: 读取 selected / options / disableAutoScroll
    alt disableAutoScroll = false
        OptionList->>OptionList: 自动滚动至单项
    else disableAutoScroll = true
        OptionList-->>OptionList: 跳过自动滚动
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • react-component/select#1146: 也修改了 OptionList 的自动滚动相关逻辑(滚动目标计算/行为变更),与本 PR 在自动滚动行为上存在代码级关联。

Suggested reviewers

  • zombieJ
  • afc163

庆祝诗

🐰 我在代码里轻声跳,
新的开关悄悄到,
滚动有时静又妙,
用户体验不打扰,
胡萝卜咬一口,乐逍遥 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed 标题准确地总结了拉取请求的主要变化,即向Select组件添加新的disableAutoScroll属性来控制自动滚动行为。

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

src/Select.tsx

ESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox.


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 gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

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 introduces a disableAutoScroll prop to give users control over the automatic scrolling behavior in the Select component. The changes are well-implemented, adding the prop and threading it down to the OptionList component where it's used to conditionally enable the auto-scroll logic. The documentation has also been updated accordingly. I have one suggestion regarding a potential bug with stale data in a useEffect hook due to a missing dependency, which was a pre-existing issue exacerbated by this change.

Comment thread src/OptionList.tsx

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@README.md`:
- Line 125: 文档中关于属性 disableAutoScroll 的说明不够明确,请在 README
的该属性行(disableAutoScroll)后补充一句说明其仅在单选模式下生效,且不会影响多选或带搜索的场景,以避免误解;定位到 README 中表格里包含
disableAutoScroll 的那一行,更新描述文本为“Disable auto scroll to selected option — only
applies to single-select mode; does not affect multi-select or searchable
scenarios.”

Comment thread README.md Outdated
@aeifn aeifn changed the title Add disableAutoScroll prop to control auto-scrolling behavior in the select component feat: add disableAutoScroll prop to control auto-scrolling behavior in the select component Jan 30, 2026
@codecov

codecov Bot commented Feb 2, 2026

Copy link
Copy Markdown

Codecov Report

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

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1197   +/-   ##
=======================================
  Coverage   99.43%   99.43%           
=======================================
  Files          31       31           
  Lines        1229     1229           
  Branches      439      439           
=======================================
  Hits         1222     1222           
  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.

@aeifn aeifn closed this Jun 11, 2026
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.

1 participant