Skip to content

fix: support pointer events in useLongPress#2947

Open
wanxiankai wants to merge 1 commit into
alibaba:masterfrom
wanxiankai:fix/use-long-press-pointer-events
Open

fix: support pointer events in useLongPress#2947
wanxiankai wants to merge 1 commit into
alibaba:masterfrom
wanxiankai:fix/use-long-press-pointer-events

Conversation

@wanxiankai

Copy link
Copy Markdown

This is a ...

  • New feature
  • Bug fix
  • Site / documentation update
  • Demo update
  • TypeScript definition update
  • Bundle size optimization
  • Performance optimization
  • Enhancement feature
  • Internationalization
  • Refactoring
  • Code style optimization
  • Test Case
  • Branch merge
  • Other (about what?)

Related issue link

Fixes #2861

Background and solution

useLongPress previously listened to mouse and touch events only. In environments such as Tauri WebView on macOS, pointer events can be delivered while the mouse/touch path is unreliable, so long press never starts.

This change uses PointerEvent listeners when they are supported and keeps the existing mouse/touch listeners as a fallback for older environments. The pointer path shares the same click/long-press-end behavior as the fallback path and also clears pending presses on pointer leave/cancel.

Changelog

Language Changelog
English Add PointerEvent support to useLongPress while preserving mouse/touch fallback behavior.
Chinese useLongPress 支持 PointerEvent,同时保留 mouse/touch 兜底行为。

Self Check before Merge

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • TypeScript definition is updated/provided or not needed
  • Changelog is provided or not needed

Test

  • pnpm exec vitest run src/useLongPress/__tests__/index.spec.ts from packages/hooks
  • pnpm --filter=ahooks tsc
  • pnpm --filter=ahooks test

@CLAassistant

CLAassistant commented Jul 18, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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.

useLongPress 在 macOS 的 Tauri 应用中无法生效。

2 participants