Skip to content

Commit 9d0bb7e

Browse files
committed
fix(ContextMenu): a held finger opens the menu at UIKit's long press, with none of the hold options meta#8670 cut (spec:AST-094 FR43)
meta#8670 cuts the context request's two-stage hold (commitMs, requestMs, requestOnLift), allowableMovement and isPerAxis, as asked there: the hold is UIKit's long press and requests as it begins. ContextMenu and the factory passed them for UIContextMenuInteraction's 400 ms commit, 735 ms menu, open at a lift and 11.5 pt on each axis. They pass none now: under any primary pointer a held finger gets the menu at 500 ms, a lift before it is a tap, and a drift past 10 pt (a distance) opens nothing. Under the touch model the commit, now the long press, plays the haptic and the press feedback plays UIKit's press curve until the menu shows. The UIKit table's per-axis drift guess has no reader left and goes. The tests, the interaction specs, the docs, the story and the changesets that described the two-stage hold describe the long press; the tests of a lift after the commit and of a drag between the commit and the menu go with that window.
1 parent 73930e9 commit 9d0bb7e

14 files changed

Lines changed: 238 additions & 303 deletions

‎.changeset/contextmenu-press-constants.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
'@astryxdesign/cli': patch
44
---
55

6-
[chore] The UIKit constants table gains ContextMenu's touch timeline as measured on iOS 26.2: the press feedback starts at 150 ms, the press commits at 400 ms, and the menu displays at 735 ms. It also records the drift tolerance, and the press feedback's growth, spring and display latency. A closed-form press-feedback curve, checked against UIKit's per-frame presentation, comes with them. ContextMenu's touch timeline uses them.
6+
[chore] The UIKit constants table gains ContextMenu's touch timeline as measured on iOS 26.2: the press feedback starts at 150 ms, the press commits at 400 ms, and the menu displays at 735 ms. It also records the press feedback's growth, spring and display latency. A closed-form press-feedback curve, checked against UIKit's per-frame presentation, comes with them. ContextMenu's press feedback uses them.
77

88
@vjeux

‎.changeset/contextmenu-touch-timeline.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
'@astryxdesign/core': patch
33
---
44

5-
[feat] ContextMenu opens from a held finger on iOS 26's measured timeline, on every touch device (a coarse primary pointer, iOS and Android alike). The trigger starts to grow at 150 ms (the onset of core's one press machine), following UIKit's measured press curve on the compositor, and the hold runs on the trigger's context request with UIKit's measured moments. At 400 ms the press takes the finger: its lift no longer sends a click, and the page cannot scroll under it. The menu opens at 735 ms if the finger is still down, or as soon as it lifts after 400 ms. A finger that lifts before 400 ms, or drifts more than 11.5 px on either axis before the menu opens, gets no menu, and the trigger springs back. The page stays still while the menu is up, and the trigger returns to its size when the menu closes. A touch open lights no row: the menu takes the focus, and a row lights only under the finger, as in UIKit (keyboard and pointer opens still focus the first item). A second finger cancels the press, and Android's own long-press menu no longer opens a second menu. A fine pointer (a mouse) keeps the right-click menu, and UIKit's timeline stays off there.
5+
[feat] ContextMenu opens from a held finger as on iOS, on every touch device (a coarse primary pointer, iOS and Android alike). The trigger starts to grow at 150 ms (the onset of core's one press machine), following UIKit's measured press curve on the compositor, and the hold is the trigger's context request: UIKit's long press. At 500 ms the press takes the finger and the menu opens: its lift sends no click, and the page cannot scroll under it. A finger that lifts before 500 ms, or drifts more than 10 px before it, gets no menu, and the trigger springs back. The page stays still while the menu is up, and the trigger returns to its size when the menu closes. A touch open lights no row: the menu takes the focus, and a row lights only under the finger, as in UIKit (keyboard and pointer opens still focus the first item). A second finger cancels the press, and Android's own long-press menu no longer opens a second menu. A fine pointer (a mouse) keeps the right-click menu, with no press feedback.
66

77
@vjeux

‎apps/storybook/stories/ContextMenu.stories.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ export const TouchLongPress: Story = {
611611
docs: {
612612
description: {
613613
story:
614-
'On a touch screen (iOS or Android), hold a finger on the card. As on iOS, it starts to grow after 150 ms, a haptic plays at 400 ms where the device can play one, and the menu opens at 735 ms, or as soon as the finger lifts after 400 ms. A finger that lifts before 400 ms, or drifts more than 11.5 px on either axis before the menu opens, gets no menu, and the card springs back. While the menu is up the page stays still, and the card returns to its size when the menu closes.',
614+
'On a touch screen (iOS or Android), hold a finger on the card. As on iOS, it starts to grow after 150 ms; at 500 ms, UIKit’s long press, a haptic plays where the device can play one and the menu opens. A finger that lifts before 500 ms, or drifts more than 10 px before it, gets no menu, and the card springs back. While the menu is up the page stays still, and the card returns to its size when the menu closes.',
615615
},
616616
},
617617
},
@@ -642,7 +642,7 @@ export const TouchLongPressPopover: Story = {
642642
docs: {
643643
description: {
644644
story:
645-
'With `presentation="popover"`, ContextMenu keeps today’s menu on every device: a finger held for 500 ms opens it at the finger, with no growth and no iOS timeline. A finger on a device whose primary pointer is fine (a mouse or a trackpad) gets the same long press.',
645+
'With `presentation="popover"`, ContextMenu keeps today’s menu on every device: a finger held for 500 ms opens it at the finger, with no growth. A finger on a device whose primary pointer is fine (a mouse or a trackpad) gets the same long press.',
646646
},
647647
},
648648
},

‎packages/core/src/ContextMenu/ContextMenu.doc.mjs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ export const docs = {
159159
usage: {
160160
anatomy,
161161
description:
162-
'A right-click context menu that appears at the cursor position. Use to provide contextual actions for specific elements or regions without cluttering the UI with visible buttons. Under a finger, on every touch device, a held finger opens it with iOS timing: the trigger starts to grow at 150 ms, and the menu opens at 735 ms, or as soon as the finger lifts after 400 ms. A block trigger then lifts out of the page, as on iOS: it grows about 13% over a tinted backdrop, and the menu grows out of the finger to sit beside it, below when it fits and above otherwise.',
162+
'A right-click context menu that appears at the cursor position. Use to provide contextual actions for specific elements or regions without cluttering the UI with visible buttons. Under a finger, on every touch device, a held finger opens it at UIKit’s long press, 500 ms; the trigger starts to grow at 150 ms, as on iOS. A block trigger then lifts out of the page, as on iOS: it grows about 13% over a tinted backdrop, and the menu grows out of the finger to sit beside it, below when it fits and above otherwise.',
163163
bestPractices: [
164164
{
165165
guidance: true,
@@ -228,7 +228,7 @@ export const docs = {
228228
export const docsZh = {
229229
usage: {
230230
description:
231-
'右键点击时在光标位置出现的上下文菜单。用于为特定元素或区域提供上下文操作,而不使 UI 杂乱。在所有触摸设备上,按住手指即可打开,时序与 iOS 相同:150 毫秒时触发区域开始放大,735 毫秒时菜单打开;若手指在 400 毫秒后抬起,菜单在抬起时立即打开。随后块级触发区域会像 iOS 一样从页面中浮起:它在着色背景上放大约 13%,菜单从手指处展开并位于其旁边,空间足够时在下方,否则在上方。',
231+
'右键点击时在光标位置出现的上下文菜单。用于为特定元素或区域提供上下文操作,而不使 UI 杂乱。在所有触摸设备上,按住手指 500 毫秒(UIKit 的长按)即可打开;与 iOS 一样,触发区域在 150 毫秒时开始放大。随后块级触发区域会像 iOS 一样从页面中浮起:它在着色背景上放大约 13%,菜单从手指处展开并位于其旁边,空间足够时在下方,否则在上方。',
232232
bestPractices: [
233233
{guidance: true, description: '保持菜单项简洁和面向操作。'},
234234
{guidance: true, description: '有很多项时使用分组和分隔线。'},
@@ -269,7 +269,7 @@ export const docsDense = {
269269
usage: {
270270
anatomy,
271271
description:
272-
'A right-click context menu that appears at the cursor position. Use to provide contextual actions for specific elements or regions. Under a finger (any touch device): a held finger opens it at 735 ms, or on a lift after 400 ms; the trigger grows from 150 ms, then a block trigger lifts (about 13%) over a tint with the menu below or above it.',
272+
'A right-click context menu that appears at the cursor position. Use to provide contextual actions for specific elements or regions. Under a finger (any touch device): a held finger opens it at 500 ms (UIKit’s long press); the trigger grows from 150 ms, then a block trigger lifts (about 13%) over a tint with the menu below or above it.',
273273
bestPractices: [
274274
{guidance: true, description: 'Keep items concise and action-oriented.'},
275275
{

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

Lines changed: 22 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -785,22 +785,11 @@ describe.each([
785785
drifting.up();
786786
});
787787

788-
it('opens for a finger still down at 735 ms (iOS 26.2), not a millisecond before', () => {
789-
const trigger = renderMenu();
790-
const press = finger(trigger);
791-
press.down();
792-
advance(contextMenu.press.menuDisplayMs - 1);
793-
expect(menuShows()).toBe(0);
794-
advance(1);
795-
expect(menuShows()).toBe(1);
796-
press.up();
797-
});
798-
799788
it('lights no row when a touch opens it: focus goes to the menu itself, not its first item', () => {
800789
const trigger = renderMenu();
801790
const press = finger(trigger);
802791
press.down();
803-
advance(contextMenu.press.menuDisplayMs);
792+
advance(LONG_PRESS_DURATION_MS);
804793
// The focus moves on the next frame.
805794
advance(20);
806795
expect(screen.getByRole('menu', {hidden: true})).toHaveFocus();
@@ -810,35 +799,11 @@ describe.each([
810799
press.up();
811800
});
812801

813-
it('opens at the lift for a finger lifted after the commit (400 ms), as UIKit does', () => {
814-
const trigger = renderMenu();
815-
const press = finger(trigger);
816-
press.down();
817-
advance(529);
818-
expect(menuShows()).toBe(0);
819-
act(() => {
820-
press.up();
821-
});
822-
expect(menuShows()).toBe(1);
823-
});
824-
825-
it('opens nothing for a drag past the tolerance after the commit, before the menu', () => {
826-
const trigger = renderMenu();
827-
const press = finger(trigger, 1, 20, 20);
828-
press.down();
829-
advance(500);
830-
press.moveTo(20, 50);
831-
advance(500);
832-
press.up();
833-
advance(100);
834-
expect(menuShows()).toBe(0);
835-
});
836-
837802
it('keeps the menu open as the finger lifts: the lift sends no click or compatibility mouse events', () => {
838803
const trigger = renderMenu();
839804
const press = finger(trigger);
840805
press.down();
841-
advance(contextMenu.press.menuDisplayMs);
806+
advance(LONG_PRESS_DURATION_MS);
842807
const lift = press.up();
843808
// A cancelled touchend is the one signal that stops the browser's click
844809
// and its compatibility mousedown, which would read as a press outside.
@@ -847,13 +812,13 @@ describe.each([
847812
expect(HTMLElement.prototype.hidePopover).not.toHaveBeenCalled();
848813
});
849814

850-
it('still opens at 735 ms beside a consumer onTouchStart, which runs (#7167)', () => {
815+
it('still opens at the long press beside a consumer onTouchStart, which runs (#7167)', () => {
851816
const onTouchStart = vi.fn();
852817
const trigger = renderMenu({onTouchStart});
853818
const press = finger(trigger);
854819
press.down();
855820
expect(onTouchStart).toHaveBeenCalledTimes(1);
856-
advance(contextMenu.press.menuDisplayMs - 1);
821+
advance(LONG_PRESS_DURATION_MS - 1);
857822
expect(menuShows()).toBe(0);
858823
advance(1);
859824
expect(menuShows()).toBe(1);
@@ -890,7 +855,7 @@ describe.each([
890855
);
891856
const press = finger(screen.getByTestId('ctx'));
892857
press.down();
893-
advance(contextMenu.press.menuDisplayMs);
858+
advance(LONG_PRESS_DURATION_MS);
894859
expect(menuShows()).toBe(1);
895860
press.up();
896861
});
@@ -917,13 +882,13 @@ describe.each([
917882
press.up();
918883
});
919884

920-
it('still opens after a drift inside the tolerance', () => {
885+
it('still opens after a drift inside UIKit\u2019s 10 pt, measured as a distance', () => {
921886
const trigger = renderMenu();
922887
const press = finger(trigger, 1, 20, 20);
923888
press.down();
924889
advance(50);
925-
press.moveTo(31, 31); // 15.6 px away, 11 px on each axis
926-
advance(contextMenu.press.menuDisplayMs);
890+
press.moveTo(27, 27); // 9.9 px away
891+
advance(LONG_PRESS_DURATION_MS);
927892
expect(menuShows()).toBe(1);
928893
press.up();
929894
});
@@ -955,12 +920,12 @@ describe.each([
955920
trigger.dispatchEvent(native);
956921
expect(native.defaultPrevented).toBe(true);
957922
expect(menuShows()).toBe(0);
958-
advance(contextMenu.press.menuDisplayMs - 380);
923+
advance(LONG_PRESS_DURATION_MS - 380);
959924
expect(menuShows()).toBe(1);
960925
press.up();
961926
});
962927

963-
it('plays the click haptic at the commit where the platform vibrates, and none for an early lift', () => {
928+
it('plays the click haptic at the long press where the platform vibrates, and none for an early lift', () => {
964929
const vibrate = vi.fn(() => true);
965930
Object.defineProperty(navigator, 'vibrate', {
966931
value: vibrate,
@@ -977,12 +942,12 @@ describe.each([
977942

978943
const held = finger(trigger);
979944
held.down();
980-
advance(contextMenu.press.commitMs - 1);
945+
advance(LONG_PRESS_DURATION_MS - 1);
981946
expect(vibrate).not.toHaveBeenCalled();
982947
advance(1);
983-
// At the commit, before the menu shows.
948+
// At the commit, which is the long press: the menu shows with it.
984949
expect(vibrate).toHaveBeenCalledTimes(1);
985-
expect(menuShows()).toBe(0);
950+
expect(menuShows()).toBe(1);
986951
expect(vibrate).toHaveBeenCalledWith([
987952
...HAPTIC_VIBRATION_PATTERNS[contextMenu.commitHaptic].value,
988953
]);
@@ -997,8 +962,7 @@ describe.each([
997962
const trigger = renderMenu();
998963
const press = finger(trigger);
999964
press.down();
1000-
advance(contextMenu.press.commitMs);
1001-
// Lifted after the commit: the menu opens at the lift.
965+
advance(LONG_PRESS_DURATION_MS);
1002966
act(() => {
1003967
press.up();
1004968
});
@@ -1094,7 +1058,7 @@ describe.each([
10941058
);
10951059
const press = finger(screen.getByTestId('ctx'));
10961060
press.down();
1097-
advance(contextMenu.press.menuDisplayMs);
1061+
advance(LONG_PRESS_DURATION_MS);
10981062
press.up();
10991063
expect(onOpenChange).toHaveBeenLastCalledWith(true);
11001064
// The trigger is in the top layer itself, and an empty placeholder
@@ -1141,7 +1105,7 @@ describe.each([
11411105
);
11421106
const press = finger(screen.getByTestId('ctx'));
11431107
press.down();
1144-
advance(contextMenu.press.menuDisplayMs);
1108+
advance(LONG_PRESS_DURATION_MS);
11451109
press.up();
11461110
expect(
11471111
document.querySelector('[data-astryx-context-menu-lift]'),
@@ -1172,7 +1136,7 @@ describe.each([
11721136
).toBeNull();
11731137
const press = finger(screen.getByTestId('ctx'));
11741138
press.down();
1175-
advance(contextMenu.press.menuDisplayMs);
1139+
advance(LONG_PRESS_DURATION_MS);
11761140
press.up();
11771141
const layer = document.querySelector<HTMLElement>(
11781142
'[data-astryx-context-menu-lift]',
@@ -1193,7 +1157,7 @@ describe.each([
11931157
const trigger = renderMenu({triggerAs: 'span'});
11941158
const press = finger(trigger);
11951159
press.down();
1196-
advance(contextMenu.press.menuDisplayMs);
1160+
advance(LONG_PRESS_DURATION_MS);
11971161
expect(menuShows()).toBe(1);
11981162
expect(
11991163
document.querySelector('[data-astryx-context-menu-lift]'),
@@ -1314,7 +1278,7 @@ describe('ContextMenu: the primary pointer alone picks a finger’s rules (spec:
13141278
vi.unstubAllGlobals();
13151279
});
13161280

1317-
it('opens for the same held finger at 735 ms where the primary pointer is coarse, and at 500 ms where it is fine', () => {
1281+
it('opens for the same held finger at the long press, 500 ms, whether the primary pointer is coarse or fine', () => {
13181282
// The menu's popover only (not the lift layer or its hold's shield).
13191283
const shows = menuShows;
13201284
const renderTrigger = () => {
@@ -1325,14 +1289,14 @@ describe('ContextMenu: the primary pointer alone picks a finger’s rules (spec:
13251289
);
13261290
return {trigger: screen.getByTestId('ctx'), unmount: view.unmount};
13271291
};
1328-
// Coarse: the touch model's timeline, no menu at 500 ms.
1292+
// Coarse: the touch model, whose hold is the same long press.
13291293
stubPointer(true);
13301294
const coarse = renderTrigger();
13311295
let press = finger(coarse.trigger);
13321296
press.down();
1333-
advance(600);
1297+
advance(LONG_PRESS_DURATION_MS - 1);
13341298
expect(shows()).toBe(0);
1335-
advance(contextMenu.press.menuDisplayMs - 600);
1299+
advance(1);
13361300
expect(shows()).toBe(1);
13371301
press.up();
13381302
coarse.unmount();

0 commit comments

Comments
 (0)