Skip to content

Commit fc210bc

Browse files
committed
feat(core): createMenuPress runs the menu press model without React
createMenuPress(menu, options) runs the press model on any element: the row under a release acts, the highlight follows a held pointer, a mouse press on the trigger opens the menu, and a finger held on it opens it after the long-press delay, on the shared long-press detector. It keeps the options it is created with, and destroy() removes every listener it added. useMenuPress(menuRef, options) is its React form, with nothing to spread. It calls the latest callbacks, reads only committed options, and creates a new factory when the menu, its document, the trigger, a value option or the set of given callbacks changes. ContextMenu, DropdownMenuSubMenu, MenuBottomSheetActionList, Selector and TabMenu use it. ContextMenu's press rides its menu element, which carries the press marker in its markup as before, never the items sheet's container, so the sheet's Back keeps its press paint. The options form is unchanged, and its doc keeps its returns. useLongPressDetector folds into useLongPress, since the menu press runs the detector directly. The core API report gains the factory, its types and the ref form. The DropdownMenu record proposes that the trigger props' press handlers leave only with a ref path, and the useMenuPress record that the options form is deprecated together with its callers' migration, both pending owner review.
1 parent 5719467 commit fc210bc

18 files changed

Lines changed: 1324 additions & 811 deletions

‎.changeset/create-menu-press.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astryxdesign/core': patch
3+
---
4+
5+
[feat] `createMenuPress(menu, options)` runs the menu press model on any element without React: the row under a release acts, the highlight follows a held pointer, a mouse press on `trigger` opens the menu, and a finger held on it opens it after the long-press delay. It keeps the options it is created with, and `destroy()` removes every listener it added. `useMenuPress(menuRef, options)` is its React form: `triggerRef` names the trigger, and there is nothing to spread. Its press exists only while the menu element is mounted, the trigger's included, so a menu rendered only while open opens on its trigger's click alone; press-to-open there keeps the options form. The options form, `useMenuPress({menuRef, …})` with its `menuProps` and `triggerProps`, works as before.
6+
7+
@vjeux

‎docs/specs/components/DropdownMenu/DropdownMenu.spec.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,18 @@ pattern requires; Escape and a press outside close it. Without either prop
545545
the component is unchanged: a Menu Button whose Tab closes the menu. Rejected:
546546
closing on Tab past either end, which leaves a modal dialog by Tab.
547547

548+
### DEC-11 (proposed) — The trigger's press handlers leave only with a ref path
549+
550+
**Reference:** `component:DropdownMenu/DEC-11`
551+
552+
**Decider:** proposed by `vjeux`, `2026-11-02`; pending owner review
553+
554+
`DropdownMenuTriggerProps.onPointerDown` and `onContextMenu` carry the menu's
555+
press to a `renderTrigger` control until the control's `ref` carries it.
556+
They are deprecated and removed only together with that path and the migration
557+
of every maintained caller (`spec:AST-017` FR29c). No patch deprecates them
558+
without a working replacement.
559+
548560
## Open questions
549561

550562
- **OQ1 — Which shared owner should make disabled menu rows keyboard-discoverable

‎docs/specs/components/DropdownMenu/modules/useMenuPress.spec.md‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ adopter.
9090
- Compatibility class: additive public hook and types; behavior change inside
9191
the menu family
9292
- Migration decision: `module:DropdownMenu/useMenuPress/DEC-3`; proposed
93-
`module:DropdownMenu/useMenuPress/DEC-4` (pending owner review);
93+
`module:DropdownMenu/useMenuPress/DEC-4` and
94+
`module:DropdownMenu/useMenuPress/DEC-9` (pending owner review);
9495
`spec:AST-094` FR25 (a caller that needs the released 500 ms wait passes
9596
`longPressDelayMs: 500`)
9697

@@ -326,6 +327,18 @@ the open, so a screen reader hears one open and one close.
326327

327328
Rejected: opening a sub-menu when a finger rests on its row.
328329

330+
### DEC-9 (proposed) — The options form is deprecated with its callers' migration
331+
332+
**Reference:** `module:DropdownMenu/useMenuPress/DEC-9`
333+
**Decider:** proposed by `vjeux`, `2026-11-02`; pending owner review
334+
335+
`useMenuPress(menuRef, options)` delegates to `createMenuPress`, as
336+
`architecture:public-component-api` INV22 asks. The options form,
337+
`useMenuPress({menuRef, …})`, is deprecated under INV9 only in the patch that
338+
migrates every maintained caller (`spec:AST-017` FR29c). DropdownMenu's
339+
trigger and the menus that track only presses on their items stay on it until
340+
the ref form can start a press only on an item.
341+
329342
## Open questions
330343

331344
- **OQ1 — Is press-to-open the menu family's trigger model?** (`human-design`)
@@ -334,6 +347,10 @@ Rejected: opening a sub-menu when a finger rests on its row.
334347
a finger is `spec:AST-094` FR29's. Until the owner rules, the current record's FR1–FR7
335348
stand on their own.
336349

350+
- **OQ2 — Does the options form wait for its callers' migration?** (`human-api`)
351+
Proposed DEC-9 waits on this owner decision. Until the owner rules, the
352+
options form is not deprecated.
353+
337354
The former browser-evidence question is resolved: the touch pan, the finger
338355
slide and its stray click cannot be exercised in jsdom, and real-Chromium
339356
evidence for them now exists in

‎internal/eslint-plugin-astryx/no-raw-private-attribute.baseline.json‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,13 @@
120120
"data-astryx-press"
121121
],
122122
"packages/core/src/gestures/touchActionRule.ts": ["data-astryx-touch-action"],
123+
"packages/core/src/hooks/createMenuPress.ts": [
124+
"data-astryx-menu-press-surface"
125+
],
123126
"packages/core/src/hooks/useAnnounce.ts": [
124127
"data-astryx-live-region",
125128
"data-astryx-modal-live-region"
126129
],
127-
"packages/core/src/hooks/useMenuPress.ts": ["data-astryx-menu-press-surface"],
128130
"packages/core/src/theme/Theme.tsx": [
129131
"data-astryx-id",
130132
"data-astryx-id",

‎packages/core/api-report.md‎

Lines changed: 36 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/core/src/ContextMenu/ContextMenu.test.tsx‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
import userEvent from '@testing-library/user-event';
2424
import {readFileSync} from 'node:fs';
2525
import {ContextMenu} from './ContextMenu';
26+
import {MENU_PRESS_MARKER} from '../hooks/menuPressMarker';
2627
import {ContextMenuGroup} from './index';
2728
import {
2829
ContextMenuItem,
@@ -293,6 +294,40 @@ describe('ContextMenu', () => {
293294
expect(HTMLElement.prototype.showPopover).not.toHaveBeenCalled();
294295
});
295296

297+
it('keeps a menuContent touch sheet as the press root of its rows', async () => {
298+
render(
299+
<ContextMenu
300+
presentation="bottom-sheet"
301+
label="Row actions"
302+
menuContent={<DropdownMenuItem label="Rename" />}>
303+
<div>Right-click me</div>
304+
</ContextMenu>,
305+
);
306+
fireEvent.contextMenu(screen.getByText('Right-click me'));
307+
const row = await screen.findByRole('menuitem', {name: 'Rename'});
308+
// The rows leave their press paint to the press root they sit in.
309+
expect(row.closest(`[${MENU_PRESS_MARKER}]`)).not.toBeNull();
310+
});
311+
312+
it('keeps the items sheet out of the press model, so its Back button keeps its press paint', async () => {
313+
const user = userEvent.setup();
314+
render(
315+
<ContextMenu
316+
presentation="bottom-sheet"
317+
label="Row actions"
318+
items={[{label: 'Move to project', items: [{label: 'Apollo launch'}]}]}>
319+
<div>Right-click me</div>
320+
</ContextMenu>,
321+
);
322+
fireEvent.contextMenu(screen.getByText('Right-click me'));
323+
await user.click(
324+
await screen.findByRole('button', {name: 'Move to project'}),
325+
);
326+
const back = await screen.findByRole('button', {name: 'Back'});
327+
// The press feedback skips any element inside a press root.
328+
expect(back.closest(`[${MENU_PRESS_MARKER}]`)).toBeNull();
329+
});
330+
296331
it('drills into nested data items inside the BottomSheet', async () => {
297332
const user = userEvent.setup();
298333
const onMove = vi.fn();

‎packages/core/src/ContextMenu/ContextMenu.tsx‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ import {useMenuOverflow} from '../DropdownMenu/useMenuOverflow';
7777
import {useMenuDrillIn} from '../DropdownMenu/useMenuDrillIn';
7878
import {useInternalListFocus} from '../hooks/useListFocus';
7979
import {useMenuPress} from '../hooks/useMenuPress';
80+
import {MENU_PRESS_MARKER} from '../hooks/menuPressMarker';
8081
import {useTypeahead} from '../hooks/useTypeahead';
8182
import {useLongPress} from '../hooks/useLongPress';
8283
import {layerAnimations} from '../Layer/layerAnimations.stylex';
@@ -749,25 +750,32 @@ export function ContextMenu({
749750

750751
// The press model: the row under a release acts, the highlight follows a
751752
// held pointer, a mouse released outside dismisses and a finger leaves the
752-
// menu open.
753-
const menuPress = useMenuPress({
754-
menuRef: listRef,
753+
// menu open. It runs on the menu element only, never on the items sheet's
754+
// container. That container's Back keeps its press paint, which skips
755+
// anything inside a press root.
756+
const pressMenuRef = useRef<HTMLDivElement>(null);
757+
const menuElementRef = useMergedRefs(listRef, pressMenuRef);
758+
// The touch sheet mounts the menu in its lazy boundary's own commit, before
759+
// the press attaches. The marker is in the markup, so the menu carries it
760+
// from its first paint.
761+
const pressMarker = {[MENU_PRESS_MARKER]: ''};
762+
useMenuPress(pressMenuRef, {
755763
itemSelector: MENU_ITEM_SELECTOR,
756764
onDismiss: closeMenu,
757765
isEnabled: !usesBottomSheet,
758766
});
759767

760768
const renderedMenu = (
761769
<div
762-
ref={listRef}
770+
ref={menuElementRef}
771+
{...pressMarker}
763772
id={menuId}
764773
role="menu"
765774
data-autofocus={usesBottomSheet ? '' : undefined}
766775
tabIndex={usesBottomSheet ? 0 : -1}
767776
aria-label={label}
768777
onKeyDown={listKeyDown}
769778
onContextMenu={e => e.preventDefault()}
770-
{...menuPress.menuProps}
771779
{...mergeProps(
772780
themeProps('context-menu'),
773781
stylex.props(

‎packages/core/src/DropdownMenu/DropdownMenuSubMenu.tsx‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,8 +1044,7 @@ export function DropdownMenuSubMenu(
10441044
// The press model for this flyout: the row under a release acts, the
10451045
// highlight follows a held pointer. A mouse released outside every level
10461046
// dismisses the whole menu; a finger leaves it open.
1047-
const menuPress = useMenuPress({
1048-
menuRef,
1047+
useMenuPress(menuRef, {
10491048
itemSelector: MENU_ITEM_SELECTOR,
10501049
onDismiss: nestedMenuContext.closeMenu,
10511050
});
@@ -1274,7 +1273,6 @@ export function DropdownMenuSubMenu(
12741273
onFocus={handleMenuFocus}
12751274
onBlur={handleMenuBlur}
12761275
data-testid={menuDataTestId}
1277-
{...menuPress.menuProps}
12781276
{...surfaceOwnerProps}
12791277
{...stylex.props(
12801278
regionStyles.menu,
@@ -1312,7 +1310,6 @@ export function DropdownMenuSubMenu(
13121310
inert={!isTopView}
13131311
onKeyDown={handleContentKeyDown}
13141312
data-testid={menuDataTestId}
1315-
{...menuPress.menuProps}
13161313
{...stylex.props(
13171314
drillInStyles.list,
13181315
!isTopView && drillInStyles.hidden,
@@ -1336,7 +1333,6 @@ export function DropdownMenuSubMenu(
13361333
onFocus={handleMenuFocus}
13371334
onBlur={handleMenuBlur}
13381335
data-testid={menuDataTestId}
1339-
{...menuPress.menuProps}
13401336
{...surfaceOwnerProps}
13411337
{...stylex.props(
13421338
regionStyles.menu,
@@ -1370,7 +1366,6 @@ export function DropdownMenuSubMenu(
13701366
onMouseEnter={contentProps.onMouseEnter}
13711367
onMouseLeave={contentProps.onMouseLeave}
13721368
data-testid={menuDataTestId}
1373-
{...menuPress.menuProps}
13741369
{...mergeProps(
13751370
themeProps('dropdown-menu', {presentation: 'popover'}),
13761371
stylex.props(

‎packages/core/src/DropdownMenu/MenuBottomSheetActionList.tsx‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ export function MenuBottomSheetActionList({
7474
// The press model: the row under a finger's RELEASE acts, and the
7575
// highlight (focus) follows the finger across the rows. The sheet is modal,
7676
// so a release outside it is the scrim's, not a dismissal of ours.
77-
const menuPress = useMenuPress({
78-
menuRef: listRef,
77+
useMenuPress(listRef, {
7978
itemSelector: SHEET_ROW_SELECTOR,
8079
});
8180

@@ -148,11 +147,7 @@ export function MenuBottomSheetActionList({
148147
};
149148

150149
return (
151-
<List
152-
ref={listComposedRef}
153-
density="spacious"
154-
xstyle={styles.list}
155-
{...menuPress.menuProps}>
150+
<List ref={listComposedRef} density="spacious" xstyle={styles.list}>
156151
{items.map((option, index) => {
157152
if ('type' in option && option.type === 'divider') {
158153
return (

‎packages/core/src/Selector/Selector.tsx‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,8 +1412,7 @@ export function Selector<T extends SelectorOptionType>(
14121412
filteredItems.length,
14131413
surface.isOpen,
14141414
);
1415-
const listboxPress = useMenuPress({
1416-
menuRef: listboxRef,
1415+
useMenuPress(listboxRef, {
14171416
itemSelector: '[role="option"]:not([aria-disabled="true"])',
14181417
onHighlight: row => {
14191418
if (row == null) {
@@ -1834,7 +1833,6 @@ export function Selector<T extends SelectorOptionType>(
18341833
id={listboxId}
18351834
role="listbox"
18361835
aria-labelledby={triggerId}
1837-
{...listboxPress.menuProps}
18381836
{...stylex.props(
18391837
styles.dropdown,
18401838
listboxHasOverflow
@@ -1852,7 +1850,6 @@ export function Selector<T extends SelectorOptionType>(
18521850
ref={attachListbox}
18531851
id={listboxId}
18541852
role="listbox"
1855-
{...listboxPress.menuProps}
18561853
// The bottom sheet is a modal layer, so Chromium drops the trigger
18571854
// outside it from the accessibility tree and a reference to it yields
18581855
// no name. Name only this no-search sheet directly from the component's

0 commit comments

Comments
 (0)