Skip to content

Commit e01d233

Browse files
committed
feat(ContextMenu): a held finger lifts the trigger as iOS 26 does, with the menu beside it
1 parent 2e99126 commit e01d233

32 files changed

Lines changed: 2100 additions & 116 deletions
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@astryxdesign/core': patch
3+
'@astryxdesign/cli': patch
4+
---
5+
6+
[feat] Under a finger, on every touch device (iOS and Android alike), a ContextMenu opened by a held finger now presents as iOS 26's does. A copy of a block trigger lifts out of the page, the trigger hidden under it: it grows on from the press to 26 px larger on its longer side (15% at most), with the theme's high shadow fading in under it, over a light tint, and it stays 16 px from the screen's sides and 20 px (plus the safe area) from its top and bottom. A tap on the tint closes the menu. The menu sits 16 px from the copy, below it when it fits and above it otherwise, centered on it or flush with the edge it is held against (right-to-left pages included), and its content enters from a blur, with no row lit until the finger moves onto one. Closing returns the copy to the trigger. Under Reduce Motion the animator cross-fades everything in place instead, in 200 ms, as the reduced-motion design record asks: nothing travels, grows or blurs. Inline triggers, pointer opens and the bottom sheet are unchanged. A fine pointer keeps today's menu at the cursor.
7+
8+
The tint is a new theme token, `--color-background-backdrop-muted`: UIKit's context-menu tint (#16152A at 21%) by default, the paler form of the modal dim, and a theme can set its own. The lift's morph spring is a motion role a theme can retune; `astryx docs tokens` and `astryx docs motion` list both.
9+
10+
@vjeux

‎packages/cli/assets/docs/motion.doc.mjs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,12 @@ const calmTheme = defineTheme({
184184
headers: ['Role', 'CSS variable', 'Kind', 'Default'],
185185
rows: [
186186
// motion-roles:start (generated by scripts/generate-motion-roles.mjs)
187+
[
188+
'contextMenu.lift.morphSpring',
189+
'--motion-context-menu-lift-morph-spring',
190+
'spring',
191+
'0.3s 0.2',
192+
],
187193
[
188194
'contextMenu.press.feedbackLatencyMs',
189195
'--motion-context-menu-press-feedback-latency-ms',

‎packages/cli/assets/docs/tree/tokens-color.doc.mjs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ export const docs = {
159159
"rgba(0, 0, 0, 0.2)",
160160
"rgba(0, 0, 0, 0.48)"
161161
],
162+
[
163+
"--color-background-backdrop-muted",
164+
"rgba(22, 21, 42, 0.21)",
165+
"rgba(22, 21, 42, 0.21)"
166+
],
162167
[
163168
"--color-success",
164169
"#0D8626",

‎packages/cli/assets/docs/tree/tokens.doc.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// AUTO-GENERATED — do not edit manually.
44
// Run: node scripts/generate-token-docs.mjs
5-
// Total: 264 tokens across 15 categories.
5+
// Total: 265 tokens across 15 categories.
66

77
/** @type {import('@astryxdesign/cli/authoring').NamespaceDoc} */
88
export const docs = {

‎packages/cli/assets/theme.template.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ export const myTheme = defineTheme({
207207
//
208208
// The families, so you know what exists:
209209
// --color-* accent, on-accent · background-{body,surface,card,popover,
210-
// muted,inverted,backdrop} · text-* · icon-* · border,
210+
// muted,inverted,backdrop{,-muted}} · text-* · icon-* · border,
211211
// border-emphasized · overlay{,-hover,-pressed} ·
212212
// success/warning/error (+ -muted, on-*) · skeleton, track,
213213
// shadow, tint-hover · categorical {blue,cyan,gray,green,

‎packages/cli/test/__golden__/no-icon-set/docs-topics.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
"usage",
127127
"best-practices"
128128
],
129-
"skeleton": "adb2b618de86a4fd79d606066599ea5b41778319827b13bcf877089a6d4e4707",
129+
"skeleton": "7d6530c38a460b592159b7544a9a03c5a3573b6ee524c75d1938da4e18bc34d2",
130130
"mentions": []
131131
},
132132
"elevation": {
@@ -201,7 +201,7 @@
201201
"touch-motion",
202202
"best-practices"
203203
],
204-
"skeleton": "5a0cc086e0126b2ee9d89bdd4051299f012b477fae9fb16e94281d884c146bb9",
204+
"skeleton": "3fd04f36e23ca00644e3f428575a8a7130bd08f8aacb8fa9bae6009bf66d7591",
205205
"mentions": []
206206
},
207207
"principles": {

‎packages/cli/test/__golden__/no-icon-set/search-close.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"type": "search",
44
"data": {
55
"query": "close",
6-
"matchCount": 46,
6+
"matchCount": 45,
77
"results": [
88
{
99
"domain": "component",

‎packages/cli/test/__golden__/no-icon-set/search-close.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Results for "close" (20 of 46)
1+
Results for "close" (20 of 45)
22
name: AlertDialog
33
domain: component
44
package: @astryxdesign/core

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ export const docs = {
160160
usage: {
161161
anatomy,
162162
description:
163-
'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.',
163+
'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: a copy of it grows about 13% over a tinted backdrop, and the menu sits beside it, below when it fits and above otherwise.',
164164
bestPractices: [
165165
{
166166
guidance: true,
@@ -190,7 +190,7 @@ export const docs = {
190190
{
191191
guidance: true,
192192
description:
193-
'Leave a little room around a block trigger: a held finger grows it from its center, by about 6%, until the menu closes.',
193+
'Leave a little room around a block trigger: a held finger grows it from its center, by about 6%, and its lifted copy is about 13% larger while the menu is open.',
194194
},
195195
{
196196
guidance: false,
@@ -229,7 +229,7 @@ export const docs = {
229229
export const docsZh = {
230230
usage: {
231231
description:
232-
'右键点击时在光标位置出现的上下文菜单。用于为特定元素或区域提供上下文操作,而不使 UI 杂乱。在所有触摸设备上,按住手指即可打开,时序与 iOS 相同:150 毫秒时触发区域开始放大,735 毫秒时菜单打开;若手指在 400 毫秒后抬起,菜单在抬起时立即打开。',
232+
'右键点击时在光标位置出现的上下文菜单。用于为特定元素或区域提供上下文操作,而不使 UI 杂乱。在所有触摸设备上,按住手指即可打开,时序与 iOS 相同:150 毫秒时触发区域开始放大,735 毫秒时菜单打开;若手指在 400 毫秒后抬起,菜单在抬起时立即打开。随后块级触发区域会像 iOS 一样从页面中浮起:它的副本在着色背景上放大约 13%,菜单位于其旁边,空间足够时在下方,否则在上方。',
233233
bestPractices: [
234234
{guidance: true, description: '保持菜单项简洁和面向操作。'},
235235
{guidance: true, description: '有很多项时使用分组和分隔线。'},
@@ -250,7 +250,7 @@ export const docsZh = {
250250
{
251251
guidance: true,
252252
description:
253-
'块级触发区域周围请留出少量空间:按住时它会从中心放大约 6%,直到菜单关闭。',
253+
'块级触发区域周围请留出少量空间:按住时它会从中心放大约 6%,菜单打开期间它浮起的副本约大 13%。',
254254
},
255255
{
256256
guidance: false,
@@ -270,7 +270,7 @@ export const docsDense = {
270270
usage: {
271271
anatomy,
272272
description:
273-
'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.',
273+
'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.',
274274
bestPractices: [
275275
{guidance: true, description: 'Keep items concise and action-oriented.'},
276276
{
@@ -294,7 +294,7 @@ export const docsDense = {
294294
{
295295
guidance: true,
296296
description:
297-
'Leave room around a block trigger: a held finger grows it about 6%.',
297+
'Leave room around a block trigger: a held finger grows it about 6%, its lifted copy about 13%.',
298298
},
299299
{
300300
guidance: false,

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

Lines changed: 91 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,17 @@ function stubAndroidTouch() {
604604
// so every case moves the faked clock past the ones before it.
605605
let clockEpoch = 0;
606606

607+
/**
608+
* How many times the menu's popover was shown (a touch-opened menu also shows
609+
* the lift layer, its preview and backdrop).
610+
*/
611+
const menuShows = () =>
612+
vi
613+
.mocked(HTMLElement.prototype.showPopover)
614+
.mock.contexts.filter(
615+
el => !(el as HTMLElement).hasAttribute('data-astryx-context-menu-lift'),
616+
).length;
617+
607618
// One touch model on every touch device (#8316): iOS and Android alike.
608619
describe.each([
609620
['iOS', stubIosTouch],
@@ -654,9 +665,9 @@ describe.each([
654665
const press = finger(trigger);
655666
press.down();
656667
advance(contextMenu.press.menuDisplayMs - 1);
657-
expect(HTMLElement.prototype.showPopover).not.toHaveBeenCalled();
668+
expect(menuShows()).toBe(0);
658669
advance(1);
659-
expect(HTMLElement.prototype.showPopover).toHaveBeenCalledTimes(1);
670+
expect(menuShows()).toBe(1);
660671
press.up();
661672
});
662673

@@ -679,9 +690,11 @@ describe.each([
679690
const press = finger(trigger);
680691
press.down();
681692
advance(529);
682-
expect(HTMLElement.prototype.showPopover).not.toHaveBeenCalled();
683-
press.up();
684-
expect(HTMLElement.prototype.showPopover).toHaveBeenCalledTimes(1);
693+
expect(menuShows()).toBe(0);
694+
act(() => {
695+
press.up();
696+
});
697+
expect(menuShows()).toBe(1);
685698
});
686699

687700
it('opens nothing for a drag past the tolerance after the commit, before the menu', () => {
@@ -693,7 +706,7 @@ describe.each([
693706
advance(500);
694707
press.up();
695708
advance(100);
696-
expect(HTMLElement.prototype.showPopover).not.toHaveBeenCalled();
709+
expect(menuShows()).toBe(0);
697710
});
698711

699712
it('keeps the menu open as the finger lifts: the lift sends no click or compatibility mouse events', () => {
@@ -716,9 +729,9 @@ describe.each([
716729
press.down();
717730
expect(onTouchStart).toHaveBeenCalledTimes(1);
718731
advance(contextMenu.press.menuDisplayMs - 1);
719-
expect(HTMLElement.prototype.showPopover).not.toHaveBeenCalled();
732+
expect(menuShows()).toBe(0);
720733
advance(1);
721-
expect(HTMLElement.prototype.showPopover).toHaveBeenCalledTimes(1);
734+
expect(menuShows()).toBe(1);
722735
press.up();
723736
});
724737

@@ -733,7 +746,7 @@ describe.each([
733746
press.up();
734747
expect(onTouchEnd).toHaveBeenCalledTimes(1);
735748
advance(1000);
736-
expect(HTMLElement.prototype.showPopover).not.toHaveBeenCalled();
749+
expect(menuShows()).toBe(0);
737750
});
738751

739752
it('moves the recognizer to the new trigger when triggerAs swaps it: a hold on the new node opens the menu', () => {
@@ -753,7 +766,7 @@ describe.each([
753766
const press = finger(screen.getByTestId('ctx'));
754767
press.down();
755768
advance(contextMenu.press.menuDisplayMs);
756-
expect(HTMLElement.prototype.showPopover).toHaveBeenCalledTimes(1);
769+
expect(menuShows()).toBe(1);
757770
press.up();
758771
});
759772

@@ -765,7 +778,7 @@ describe.each([
765778
const lift = press.up();
766779
expect(lift.defaultPrevented).toBe(false);
767780
advance(1000);
768-
expect(HTMLElement.prototype.showPopover).not.toHaveBeenCalled();
781+
expect(menuShows()).toBe(0);
769782
});
770783

771784
it('cancels when the finger drifts past the tolerance on one axis (11.5 px)', () => {
@@ -775,7 +788,7 @@ describe.each([
775788
advance(50);
776789
press.moveTo(20, 31.6);
777790
advance(1000);
778-
expect(HTMLElement.prototype.showPopover).not.toHaveBeenCalled();
791+
expect(menuShows()).toBe(0);
779792
press.up();
780793
});
781794

@@ -786,7 +799,7 @@ describe.each([
786799
advance(50);
787800
press.moveTo(31, 31); // 15.6 px away, 11 px on each axis
788801
advance(contextMenu.press.menuDisplayMs);
789-
expect(HTMLElement.prototype.showPopover).toHaveBeenCalledTimes(1);
802+
expect(menuShows()).toBe(1);
790803
press.up();
791804
});
792805

@@ -798,7 +811,7 @@ describe.each([
798811
advance(100);
799812
dispatchTouch('touchstart', trigger, [second], [first, second]);
800813
advance(1000);
801-
expect(HTMLElement.prototype.showPopover).not.toHaveBeenCalled();
814+
expect(menuShows()).toBe(0);
802815
dispatchTouch('touchend', trigger, [first, second], []);
803816
});
804817

@@ -816,9 +829,9 @@ describe.each([
816829
});
817830
trigger.dispatchEvent(native);
818831
expect(native.defaultPrevented).toBe(true);
819-
expect(HTMLElement.prototype.showPopover).not.toHaveBeenCalled();
832+
expect(menuShows()).toBe(0);
820833
advance(contextMenu.press.menuDisplayMs - 380);
821-
expect(HTMLElement.prototype.showPopover).toHaveBeenCalledTimes(1);
834+
expect(menuShows()).toBe(1);
822835
press.up();
823836
});
824837

@@ -844,7 +857,7 @@ describe.each([
844857
advance(1);
845858
// At the commit, before the menu shows.
846859
expect(vibrate).toHaveBeenCalledTimes(1);
847-
expect(HTMLElement.prototype.showPopover).not.toHaveBeenCalled();
860+
expect(menuShows()).toBe(0);
848861
expect(vibrate).toHaveBeenCalledWith([
849862
...HAPTIC_VIBRATION_PATTERNS[contextMenu.commitHaptic].value,
850863
]);
@@ -876,7 +889,7 @@ describe.each([
876889
it('leaves the page alone for a menu a right-click opened', () => {
877890
const trigger = renderMenu();
878891
fireEvent.contextMenu(trigger, {clientX: 20, clientY: 20});
879-
expect(HTMLElement.prototype.showPopover).toHaveBeenCalledTimes(1);
892+
expect(menuShows()).toBe(1);
880893
expect(document.body.style.position).toBe('');
881894
});
882895

@@ -901,7 +914,66 @@ describe.each([
901914
const press = finger(trigger);
902915
press.down();
903916
advance(1000);
904-
expect(HTMLElement.prototype.showPopover).not.toHaveBeenCalled();
917+
expect(menuShows()).toBe(0);
918+
press.up();
919+
});
920+
921+
it('lifts a block trigger’s copy, and closes when a finger lifts on the backdrop (UIKit ends at that lift)', () => {
922+
const onOpenChange = vi.fn();
923+
render(
924+
<ContextMenu
925+
items={[{label: 'Item 1'}]}
926+
data-testid="ctx"
927+
onOpenChange={onOpenChange}>
928+
<div>Long-press me</div>
929+
</ContextMenu>,
930+
);
931+
const press = finger(screen.getByTestId('ctx'));
932+
press.down();
933+
advance(contextMenu.press.menuDisplayMs);
934+
press.up();
935+
expect(onOpenChange).toHaveBeenLastCalledWith(true);
936+
const preview = document.querySelector(
937+
'[data-astryx-context-menu-preview]',
938+
);
939+
expect(preview).not.toBeNull();
940+
expect(preview?.getAttribute('aria-hidden')).toBe('true');
941+
expect(preview?.hasAttribute('data-testid')).toBe(false);
942+
const backdrop = document.querySelector(
943+
'[data-astryx-context-menu-lift] > span',
944+
);
945+
if (backdrop == null) {
946+
throw new Error('no backdrop');
947+
}
948+
// A lift there of a finger that went down elsewhere is not a tap there.
949+
fireEvent.pointerUp(backdrop, {
950+
isPrimary: true,
951+
pointerId: 7,
952+
pointerType: 'touch',
953+
});
954+
expect(onOpenChange).toHaveBeenLastCalledWith(true);
955+
fireEvent.pointerDown(backdrop, {
956+
isPrimary: true,
957+
pointerId: 8,
958+
pointerType: 'touch',
959+
});
960+
fireEvent.pointerUp(backdrop, {
961+
isPrimary: true,
962+
pointerId: 8,
963+
pointerType: 'touch',
964+
});
965+
expect(onOpenChange).toHaveBeenLastCalledWith(false);
966+
});
967+
968+
it('keeps an inline trigger’s menu at the finger: no lift', () => {
969+
const trigger = renderMenu({triggerAs: 'span'});
970+
const press = finger(trigger);
971+
press.down();
972+
advance(contextMenu.press.menuDisplayMs);
973+
expect(menuShows()).toBe(1);
974+
expect(
975+
document.querySelector('[data-astryx-context-menu-lift]'),
976+
).toBeNull();
905977
press.up();
906978
});
907979
},

0 commit comments

Comments
 (0)