astryx icon indicating copy to clipboard operation
astryx copied to clipboard

fix(core): prevent native text selection and context menu on touch long-press (#3606)

Open Geervan opened this issue 4 months ago • 4 comments

Description

This PR resolves #3606 where performing a touch long-press on the ContextMenu trigger caused native browser behaviors (text selection highlighting and the native context menu overlay) to interfere with the custom menu items.

Root Cause

  1. Selection Highlight: When the custom menu opens directly under the user's touch hold, the browser's native text selector interprets the continuing touch input as a long-press on the menu item text (e.g. "Cut"), highlighting it in blue.
  2. Native Context Menu: Once the custom menu opens, the continuing touch is positioned over the portal-rendered menu container rather than the trigger. When the touch is released or held, the browser fires a native contextmenu event. Since the portal container did not intercept this, the event bubbled to the document root and triggered the browser's default context menu overlay.

Changes

  • Text Selection: Added userSelect: 'none' to the menu style in ContextMenu.tsx. This suppresses native browser text selection overlays on all context menu items.
  • Native Context Menu: Added onContextMenu={e => e.preventDefault()} on the div wrapper for the rendered menu container in ContextMenu.tsx. This prevents the native browser menu from spawning on top of the custom context menu.
  • Unit Tests: Added a unit test to ContextMenu.test.tsx (prevents default context menu on the opened menu container) to ensure that contextmenu events targeting the menu container are blocked and prevented from bubbling.

Verification Plan

  • Automated Tests: Ran Vitest unit tests: pnpm -F @astryxdesign/core test ContextMenu (All 32 tests passed successfully).
  • Manual Verification: Inspected via mobile touch emulation in Storybook. The custom menu opens cleanly without native text highlighting or native context menus overlaying.

Geervan avatar Jul 05 '26 21:07 Geervan

@Geervan is attempting to deploy a commit to the Meta Open Source Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Jul 05 '26 21:07 vercel[bot]

Hi @Geervan!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

meta-cla[bot] avatar Jul 05 '26 21:07 meta-cla[bot]

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

meta-cla[bot] avatar Jul 05 '26 21:07 meta-cla[bot]

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview, Comment Jul 7, 2026 12:14pm

Request Review

vercel[bot] avatar Jul 07 '26 12:07 vercel[bot]