Skip to content

Prevent scroll on focus for matched element#726

Merged
zombieJ merged 1 commit intoreact-component:masterfrom
cactuser-Lu:fix-56798
Feb 5, 2026
Merged

Prevent scroll on focus for matched element#726
zombieJ merged 1 commit intoreact-component:masterfrom
cactuser-Lu:fix-56798

Conversation

@cactuser-Lu
Copy link
Contributor

@cactuser-Lu cactuser-Lu commented Feb 4, 2026

Update focus behavior to prevent scrolling when focusing an element.
fix: ant-design/ant-design#56798

Summary by CodeRabbit

Bug Fixes

  • 修复了页面在自动聚焦元素时出现意外滚动的问题

Update focus behavior to prevent scrolling when focusing an element.
@vercel
Copy link

vercel bot commented Feb 4, 2026

@cactuser-Lu 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 @cactuser-Lu, 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 focusing an element could cause the page to scroll unexpectedly. By updating the focus mechanism to explicitly prevent scrolling, it improves the user experience by maintaining the current scroll position when an element programmatically receives focus, aligning with the reported bug fix.

Highlights

  • Focus Behavior: Modified the focus() call on matchElement to include preventScroll: true, ensuring that the browser does not automatically scroll the element into view when it receives focus.

🧠 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/Dom/focus.ts
    • Modified the matchElement?.focus() call to matchElement?.focus({ preventScroll: true }) to prevent automatic scrolling when an element is focused.
Activity
  • No specific activity (comments, reviews, etc.) has been recorded for this pull request yet.
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

coderabbitai bot commented Feb 4, 2026

走查

修改了 syncFocus 方法中的焦点调用,添加 preventScroll: true 参数以防止在聚焦匹配的元素时页面自动滚动。其余逻辑保持不变。

变更

聚合 / 文件 摘要
焦点管理修复
src/Dom/focus.ts
在 focus 调用中添加 preventScroll: true 选项,阻止焦点操作触发的页面自动滚动行为。

预估代码审查工作量

🎯 1 (简单) | ⏱️ ~3 分钟

🐰 小小焦点有大智慧,
preventScroll 来施魔法,
页面不摇不晃不抖,
抽屉打开动画顺滑,
滚动烦恼一扫而空!

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确地总结了主要变化:通过添加preventScroll: true参数来防止焦点操作时的页面滚动。
Linked Issues check ✅ Passed 代码更改通过在focus调用中添加preventScroll: true来解决问题#56798中报告的动画抖动问题,该问题由焦点操作与变换元素的滚动行为交互引起。
Out of Scope Changes check ✅ Passed 所有更改都局限于focus.ts中的焦点行为修改,直接解决了链接问题中描述的焦点滚动相关问题,没有发现超出范围的更改。

✏️ 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

Important

Action Needed: IP Allowlist Update

If your organization protects your Git platform with IP whitelisting, please add the new CodeRabbit IP address to your allowlist:

  • 136.113.208.247/32 (new)
  • 34.170.211.100/32
  • 35.222.179.152/32

Reviews will stop working after February 8, 2026 if the new IP is not added to your allowlist.


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.

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

This pull request introduces a targeted fix to prevent the page from scrolling when an element is programmatically focused as part of the focus-locking mechanism. The change adds the { preventScroll: true } option to the focus() call in syncFocus, which is the correct approach to solve this issue. This improves user experience by preventing unexpected layout shifts. The change is correct and has no side effects.

@codecov
Copy link

codecov bot commented Feb 5, 2026

Codecov Report

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

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #726   +/-   ##
=======================================
  Coverage   85.98%   85.98%           
=======================================
  Files          38       38           
  Lines        1020     1020           
  Branches      380      380           
=======================================
  Hits          877      877           
  Misses        141      141           
  Partials        2        2           

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

@zombieJ zombieJ merged commit 0820640 into react-component:master Feb 5, 2026
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.

Drawer组件设置了getContainer并且项目中使用了autofit.js,在打开时会出现动画和整体页面布局抽动的问题

2 participants