Skip to content

fix(contextmenu): touch long-press + keyboard invocation (menus-8) - #3392

Merged
cixzhang merged 3 commits into
mainfrom
navi/fix/contextmenu-touch-keyboard
Jul 3, 2026
Merged

cixzhang merged 3 commits into
mainfrom
navi/fix/contextmenu-touch-keyboard

Conversation

@cixzhang

@cixzhang cixzhang commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Part of the accessibility & keyboard-management program (#3343). Fixes finding menus-8.

Problem

ContextMenu could only be opened by a right-click contextmenu event:

  • No touch path. iOS Safari never synthesizes a contextmenu event on long-press, so context menus — including the row/cell actions that some Table plugins surface only there — were completely unreachable on iPads/phones.
  • Broken keyboard path. A keyboard-initiated contextmenu (Shift+F10 / the Menu key) fires with coordinates (0, 0) in several browsers, so the menu opened pinned to the top-left viewport corner instead of near the focused element.

Fix

  • Touch long-press. touchstart starts a 500ms timer; if the finger doesn't move more than 10px and doesn't lift, the menu opens at the touch point. touchmove past the threshold (a scroll/drag) and touchend/touchcancel clear the timer. The trigger gets WebkitTouchCallout: none so the long-press opens our menu instead of the native iOS callout.
  • Keyboard invocation. When a contextmenu event arrives with clientX/clientY === 0 and detail === 0 (keyboard-initiated), the menu anchors to e.currentTarget.getBoundingClientRect() (left/bottom) instead of the event coordinates.

Tests

Adds four ContextMenu.test.tsx cases: keyboard-invoked open (positions from the trigger rect), touch long-press opens after the threshold, and long-press cancels on a >10px move. Full ContextMenu suite green (20 tests), typecheck (incl. tests) + lint clean.

Note: this is additive to the ContextMenu Escape/focus-restore work in #3361 (both touch the same file; they will need a trivial rebase depending on merge order).

@vercel

vercel Bot commented Jul 2, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview, Comment Jul 3, 2026 2:05am

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 2, 2026
@github-actions

github-actions Bot commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

No new or modified components detected.

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.6KB 0B

Accessibility Audit

Status: No accessibility violations detected.


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

@cixzhang
cixzhang marked this pull request as ready for review July 2, 2026 17:51
@cixzhang

cixzhang commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

Fix the conflicts for this PR

@nynexman4464 nynexman4464 self-assigned this Jul 2, 2026

@nynexman4464 nynexman4464 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on android phone and windows PC. Seems to work. Context menu on mobile is a bit odd, not sure that pattern is super common, but worked well enough.

FYI on windows I had a hard time activating the menu in the component doc site since there was no focus target. I changed it to a button in the playground and was able to test that way.

https://astryx-git-navi-fixcontextmenu-touch-keyboard-fbopensource.vercel.app/playground#code=fZCxasMwEIZ3PcXhRQm4mK5NXEpNSwrt0nYrHVTr7IrIUpBPoGD87ollkmjydjp9393Pqe5gHcFQCSdHaJztgD-JntwxSOxVa4raOiymb75hF5oBvIuj9ZRfqx0Kie72rqwhNAnwai3NwO6LRL3P2cK-WUk2fmOgHKYlyrQL4sQl2rMnsmaBn4HEiLkDfaDxS_e4UZwxDNGV2AivCRpvalLWwEsQ3UHjah0v5pC8M7A6lwDbZAIowq4vh59Biz_UD8Dfzg245-PvCFKQuCPsSckyqylkj9GPM-bwEK0y-1TtP0GlVVZcmG0adGquN2w8AQ

FWIW I don't think they put the context menu button on most win keyboards anymore, but the shift+F10 shortcut still seems recognized by the os, and worked fine here (once I had a good target to test on)

@cixzhang

cixzhang commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto latest main — conflicts resolved, now mergeable. CI is running; auto-merge is armed.

@cixzhang
cixzhang force-pushed the navi/fix/contextmenu-touch-keyboard branch from 34738c7 to e49cad6 Compare July 2, 2026 22:57
@cixzhang
cixzhang merged commit 40753a7 into main Jul 3, 2026
15 checks passed
github-actions Bot added a commit that referenced this pull request Jul 3, 2026
@github-actions
github-actions Bot deleted the navi/fix/contextmenu-touch-keyboard branch July 12, 2026 06:57

This branch was successfully deployed

1 active deployment
Preview — c0d023dd Deployed Jul 3, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants