Skip to content

fix: prevent track focus from scrolling - #1093

Open
nrps9909 wants to merge 1 commit into
react-component:masterfrom
nrps9909:codex/prevent-click-focus-scroll
Open

fix: prevent track focus from scrolling#1093
nrps9909 wants to merge 1 commit into
react-component:masterfrom
nrps9909:codex/prevent-click-focus-scroll

Conversation

@nrps9909

@nrps9909 nrps9909 commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Summary

  • focus the selected handle with preventScroll when a track press starts a drag
  • keep the public Slider ref focus path unchanged
  • cover the focus options passed by the track interaction

Fixes #1060.

Verification

  • the regression failed on the exact base because focus() received no options
  • the fixed regression passes
  • full test suite: 122/122 tests and 5/5 snapshots
  • TypeScript, focused ESLint, Prettier, full ESM/CJS/declaration and Less compilation, and diff checks pass

Overlap audit

I searched current open issues and pull requests for #1060, preventScroll, and scroll-preserving focus. No implementation overlap was found.

AI assistance disclosure: Codex was used to trace the focus path, reproduce the reported behavior at the DOM API boundary, implement the scoped fix and regression, audit overlap, and run validation. The failure and passing results above were verified directly on the exact base and signed head commit.

Summary by CodeRabbit

  • 功能改进

    • 滑块通过轨道或标记改变值并聚焦手柄时,将避免页面自动滚动。
    • 手柄聚焦支持传入可选的聚焦配置。
  • 测试

    • 新增测试,验证通过轨道操作聚焦手柄时页面不会滚动。

@vercel

vercel Bot commented Aug 28, 2026

Copy link
Copy Markdown

@nrps9909 is attempting to deploy a commit to the afc163's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b751d4f5-3923-479d-af95-2613ede32c5f

📥 Commits

Reviewing files that changed from the base of the PR and between 02260ea and 498976c.

📒 Files selected for processing (3)
  • src/Handles/index.tsx
  • src/Slider.tsx
  • tests/Slider.test.js

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


Walkthrough

本次变更扩展 HandlesRef.focus 的聚焦选项,并让 Slider 在轨道点击后使用 { preventScroll: true } 聚焦手柄。新增测试验证该参数。

Changes

聚焦滚动控制

Layer / File(s) Summary
扩展手柄聚焦接口
src/Handles/index.tsx
HandlesRef.focus 现在接受可选的 FocusOptions,并将其传递给底层手柄的 focus 方法。
轨道点击聚焦控制
src/Slider.tsx, tests/Slider.test.js
轨道点击后的手柄聚焦调用传入 { preventScroll: true }。新增测试验证该参数。

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: 🔵 Low · up to 49897

Track-initiated dragging now focuses the selected handle without scrolling the page, while the public Slider focus path remains unchanged. The change is mergeable with owner awareness that browsers without reliable FocusOptions support may not preserve scroll position consistently.

Poem

小兔看见手柄轻轻亮,

preventScroll 守住页面方向,
轨道点击不再牵动画面,
FocusOptions 传递清爽,
测试敲响确认的铃铛。

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题明确概括了主要变更:阻止轨道聚焦导致页面滚动。
Linked Issues check ✅ Passed 代码通过向轨道交互触发的手柄聚焦传入 { preventScroll: true },解决了 issue #1060 中的异常滚动问题。新增测试验证了该行为。
Out of Scope Changes check ✅ Passed 所有代码和测试变更都服务于 issue #1060。HandlesRef.focus 的可选参数扩展是实现该修复所需的配套变更,未发现无关修改。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 3…
Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 3 files.

✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@codecov

codecov Bot commented Aug 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.67%. Comparing base (02260ea) to head (498976c).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1093   +/-   ##
=======================================
  Coverage   98.66%   98.67%           
=======================================
  Files          15       15           
  Lines         751      754    +3     
  Branches      224      226    +2     
=======================================
+ Hits          741      744    +3     
  Misses         10       10           

☔ View full report in Codecov by Harness.
📢 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.

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.

当Slider宽度超过外层容器时,点击Slider,滚动条位置异常

1 participant