Skip to content

fix: skip preventDefault on non-cancelable touch events in useDrag - #1101

Merged
yoyo837 merged 1 commit into
react-component:masterfrom
Pareder:fix/touch-prevent-default-cancelable
Nov 23, 2026
Merged

yoyo837 merged 1 commit into
react-component:masterfrom
Pareder:fix/touch-prevent-default-cancelable

Conversation

@Pareder

@Pareder Pareder commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1100

Problem

useDrag registers its move/end handlers as the handle's touchmove and touchend listeners, and both call event.preventDefault() unconditionally. If a drag starts while another finger is already scrolling the page, Chrome makes the rest of that touch sequence non-cancelable. It then logs this on every move and on touchend:

[Intervention] Ignored attempt to cancel a touchmove event with cancelable=false…

Fix

Only call preventDefault() when event.cancelable is true, in both handlers. Single-finger drags are unchanged: touch-action: none keeps their events cancelable, so they are still prevented.

Tests

  • New: a touch drag with non-cancelable touchmove/touchend never calls preventDefault, and onChange/onChangeComplete still fire with the right values. This test fails without the fix.
  • New: a cancelable touchmove is still prevented.
  • Manual check: Chrome DevTools device emulation and real Android device

Summary by CodeRabbit

  • 修复
    • 改进触摸拖动处理:仅在触摸事件可取消时阻止默认行为,避免对不可取消的事件执行无效操作。
    • 验证不可取消的触摸事件仍能正确触发拖动和结束回调,并确认可取消的移动事件会阻止默认行为。

@vercel

vercel Bot commented Nov 19, 2026

Copy link
Copy Markdown

@Pareder 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 Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

useDrag 现在仅在触摸事件可取消时调用 preventDefault()。新增测试覆盖不可取消的 touchmove 和 touchend,以及可取消的 touchmove。

Changes

触摸事件处理

Layer / File(s) Summary
触摸事件检查与测试
src/hooks/useDrag.ts, tests/Range.test.tsx
触摸移动和结束处理仅在事件可取消时调用 preventDefault()。新增测试验证不可取消事件不会调用该方法、回调收到的范围值为 [40, 50],以及可取消的移动事件会调用该方法一次。

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

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: zombiej, nrps9909

Merge Risk: Minimal · up to ded0a

This change stops useDrag from calling preventDefault() on touch events that cannot be canceled. That removes Chrome's intervention warnings during multi-finger scrolling while single-finger drags are still prevented. No actionable merge risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed 标题“fix: skip preventDefault on non-cancelable touch events in useDrag”与变更内容一致。变更仅在 useDrag 中对 touchmove 和 touchend 事件调用 preventDefault 前检查 event.cancelable,并新增了相关测试。标题说明了主要修复点和受影响的模块,符合关联 issue #1100 …
Linked Issues check Passed [#1100] 要求:useDrag 在不可取消的触摸事件上不调用 preventDefault()。在 head 版本的 src/hooks/useDrag.ts 中,onMouseMove(同时注册为 touchmove 监听器)改为仅在 event.cancelable 为 true 时调用 preventDefault()。onMouseUp(同时注册为 `…
Out of Scope Changes check Passed 本 PR 的变更仅包含 src/hooks/useDrag.ts(为两个触摸相关处理函数增加 event.cancelable 判断,共 +5/-2 行)和 tests/Range.test.tsx(新增两项触摸测试,+67 行)。两处变更均直接对应 #1100 的修复目标与验证需求。鼠标路径的行为未变,因为鼠标事件通常可取消,故 cancelable 判断在鼠标事件上仍会调用 `…
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

标题“fix: skip preventDefault on non-cancelable touch events in useDrag”与变更内容一致。变更仅在 useDrag 中对 touchmove 和 touchend 事件调用 preventDefault 前检查 event.cancelable,并新增了相关测试。标题说明了主要修复点和受影响的模块,符合关联 issue #1100 的目标。

Full details: Linked Issues check

Explanation

[#1100] 要求:useDrag 在不可取消的触摸事件上不调用 preventDefault()。在 head 版本的 src/hooks/useDrag.ts 中,onMouseMove(同时注册为 touchmove 监听器)改为仅在 event.cancelable 为 true 时调用 preventDefault()。onMouseUp(同时注册为 touchend 监听器)仅在 event.type === 'touchend' && event.cancelable 时调用 preventDefault()。这与 Issue 中的建议修复一致。单指拖动的事件仍可取消,因此仍会被阻止默认行为。拖动逻辑(取值计算、triggerChange、finishChange)未改动。PR 摘要报告 tests/Range.test.tsx 新增两项测试:不可取消的 touchmove/touchend 不调用 preventDefault 且回调值正确;可取消的 touchmove 仍调用一次 preventDefault。本次评估未读取测试文件内容,测试结论基于 PR 摘要。Issue 中的手动验证项不属于编码要求,不纳入评估。

Full details: Out of Scope Changes check

Explanation

本 PR 的变更仅包含 src/hooks/useDrag.ts(为两个触摸相关处理函数增加 event.cancelable 判断,共 +5/-2 行)和 tests/Range.test.tsx(新增两项触摸测试,+67 行)。两处变更均直接对应 #1100 的修复目标与验证需求。鼠标路径的行为未变,因为鼠标事件通常可取消,故 cancelable 判断在鼠标事件上仍会调用 preventDefault()。未发现与 #1100 无关的变更。

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
Fix failing CI checks

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

我是小兔,轻触滑块向前跳
不可取消时,我让默认动作继续
可取消时,再阻止它也不迟
移动与结束,范围值都记牢
新测试陪我把每一步照好

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5d3264a3-2d31-4c2f-b7de-9157dc87b0b9
Commits

Reviewing files that changed from the base of the PR and between 2dcc4f6 and ded0ab1.

Files selected for processing: 2

  • src/hooks/useDrag.ts
  • tests/Range.test.tsx

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

@Pareder

Pareder commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

@yoyo837 @zombieJ Could you please review?

@codecov

codecov Bot commented Nov 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.70%. Comparing base (2dcc4f6) to head (ded0ab1).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1101   +/-   ##
=======================================
  Coverage   98.69%   98.70%           
=======================================
  Files          15       15           
  Lines         769      770    +1     
  Branches      232      242   +10     
=======================================
+ Hits          759      760    +1     
  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.

@yoyo837
yoyo837 merged commit 844c224 into react-component:master Nov 23, 2026
11 of 12 checks passed
yanyubot added a commit to antdv-next/vue-components that referenced this pull request Nov 24, 2026
…m rc-component (#135)

* fix(virtual-list): skip preventDefault on non-cancelable scrollbar touchstart (react-component/virtual-list#396)

* fix(tour): preserve zero-valued close icon overrides (react-component/tour#112)

* fix(menu): preserve zero-valued item and expand icons (react-component/menu#897)

* fix(input): preserve zero-valued suffix content (react-component/input#205)

* fix(slider): skip preventDefault on non-cancelable touch events in useDrag (react-component/slider#1101)

* fix(image): only preventDefault on cancelable touchmove events (react-component/image#539)

* chore(sync): advance color-picker, image, input, menu, mutate-observer, rate, slider, tour and virtual-list cursors to upstream HEAD

---------

Co-authored-by: yanyubot <356405855+yanyubot@users.noreply.github.com>
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.

useDrag calls preventDefault() on non-cancelable touch events, triggering Chrome's IgnoredEventCancel intervention

2 participants