fix(core): prevent native text selection and context menu on touch long-press (#3606)
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
- 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.
- 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
contextmenuevent. 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 themenustyle inContextMenu.tsx. This suppresses native browser text selection overlays on all context menu items. - Native Context Menu: Added
onContextMenu={e => e.preventDefault()}on thedivwrapper for the rendered menu container inContextMenu.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 thatcontextmenuevents 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 is attempting to deploy a commit to the Meta Open Source Team on Vercel.
A member of the Team first needs to authorize it.
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!
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!
The latest updates on your projects. Learn more about Vercel for GitHub.
| Project | Deployment | Actions | Updated (UTC) |
|---|---|---|---|
| astryx | Preview, Comment | Jul 7, 2026 12:14pm |