[Web] GestureDetector blocks context menu by default

Đang mở
#4,687 3 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

@lassiecoder đang làm issue này rồi.

Từ ngày 12/11/2026.

  • #4692 của @lassiecoder — đang mở

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
56/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
react-native, typescript
Lĩnh vực
frontend, web-dev

Hướng nghiên cứu

Start in web/handlers/GestureHandler.ts and v3/detectors/HostGestureDetector.web.tsx, where the issue identifies the context menu defaults and reset path. Compare those paths with GestureHandlerWebDelegate.shouldDisableContextMenu and the v2 behavior described here. Add or update web tests for native context menus and onContextMenu propagation; done means the native menu is suppressed only for an explicit false setting or a gesture using MouseButton.RIGHT.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Platform: Web
Description

Since v3, every gesture handler on web blocks the browser's native context menu by default. Right-clicking anywhere inside a GestureDetector or an RNGH component (ScrollView, FlatList, Pressable, …) no longer opens the browser menu, even when the gesture doesn't use the right mouse button.

This worked in v2 (tested with 2.25.0). There, the native menu was only suppressed for gestures listening to MouseButton.RIGHT or with an explicit enableContextMenu={false}.

Why this is a problem

In a real app, whole screens will be wrapped in RNGH components (ScrollView, FlatList). contextmenu bubbles, and one preventDefault() on any ancestor cancels the browser menu. So a single default-configured handler anywhere above an element is enough to block it.

To use the native context menu or onContextMenu in an RNGH app, I now have to add enableContextMenu to every RNGH component that may contain an element with a context menu. That means nearly every GestureDetector, ScrollView and list in the app, plus third-party libraries built on RNGH that may not expose the prop. Missing one ancestor breaks it again.

enableContextMenu={true} is also not equivalent to the v2 default. It attaches a listener that calls e.stopPropagation(), so the event never reaches ancestors, including React's root listener, and onContextMenu handlers higher in the tree stop firing. In v2 the default (undefined) attached no listener at all, so both the native menu and onContextMenu worked without any extra props.

Root cause

GestureHandlerWebDelegate still uses the v2 check:

private shouldDisableContextMenu() {
  return (
    (this.gestureHandler.enableContextMenu === undefined &&
      this.gestureHandler.isButtonInConfig(MouseButton.RIGHT)) ||
    this.gestureHandler.enableContextMenu === false
  );
}

In v3, enableContextMenu can no longer be undefined, so the first branch is dead and the second always matches:

  • web/handlers/GestureHandler.ts: private _enableContextMenu: boolean = false. It is only overwritten when the config value is not undefined, and the reset path sets it back to false.
  • v3/detectors/HostGestureDetector.web.tsx → unpackDOMProps: source.enableContextMenu ?? DEFAULT_ENABLE_CONTEXT_MENU, where DEFAULT_ENABLE_CONTEXT_MENU = false.
Expected

Same as v2: only suppress the native menu when enableContextMenu={false} is passed explicitly or the gesture listens to MouseButton.RIGHT.

Steps to reproduce
  1. Render on web:

    import { GestureHandlerRootView, ScrollView } from 'react-native-gesture-handler';
    import { Text } from 'react-native';
    
    export default function App() {
      return (
        <GestureHandlerRootView style={{ flex: 1 }}>
          <ScrollView>
            <Text onContextMenu={() => console.log('onContextMenu')}>
              Right-click me
            </Text>
          </ScrollView>
        </GestureHandlerRootView>
      );
    }
    
  2. Right-click the text.

  3. With 3.4.0: no browser context menu appears.

  4. Switch to 2.25.0 and repeat: the browser context menu opens.

A link to a Gist, an Expo Snack or a link to a repository based on this template that reproduces the bug.
Gesture Handler version

3.5.0

React Native version

0.86.0

Platforms

Web

JavaScript runtime

None

Workflow

None

Build type

None

Device

None

Device model

No response

Acknowledgements

Yes

Ngôn ngữ chính
TypeScript
Star
6.8k
Fork
1.1k
Merge trung bình
1 ngày 23 giờ
Pull request đã merge (30 ngày)
46

Chuẩn bị môi trường

  • Không có Dockerfile hay tệp Docker Compose
  • Có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của software-mansion/react-native-gesture-handler

Tất cả issue của software-mansion/react-native-gesture-handler

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.