Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/menu-press-public-default.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@astryxdesign/core': patch
---

[feature] `useMenuPress` with no `longPressDelayMs` now follows DropdownMenu's finger rules on every device (`spec:AST-094` FR25, FR29, FR43): a finger or a pen opens the menu as it presses (inside a scroll view, once the 150 ms content-touch delay has passed), and the finger that opened it picks a row only after moving 10 px. To keep the previous behavior, a 500 ms hold and a pick at the opening finger's lift, pass `longPressDelayMs: 500`.

@vjeux
7 changes: 7 additions & 0 deletions .changeset/menu-press-uimenu.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@astryxdesign/core': patch
---

[feature] Under a finger or a pen, on every device, the trigger of an anchored DropdownMenu or MoreMenu now opens its menu as it is pressed, instead of after a 500 ms hold (`spec:AST-094` FR29, FR43). Inside a scroll view it opens once the 150 ms content-touch delay has passed with no scroll, so a scroll that starts on it still scrolls. To keep the previous behavior, a tap that opens at the lift and a 500 ms hold, pass `presentation="popover"`. A menu shown as a bottom sheet, and a mouse, are unchanged.

@vjeux
1 change: 1 addition & 0 deletions apps/sandbox/scripts/next-export-routes.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"/pages/markdown-perf/",
"/pages/media-mode/",
"/pages/mega-menu/",
"/pages/menu-press-cases/",
"/pages/mobile-prototypes/",
"/pages/mobile-spacing/",
"/pages/mobile-type/",
Expand Down
83 changes: 83 additions & 0 deletions apps/sandbox/src/app/(raw)/pages/menu-press-cases/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Copyright (c) Meta Platforms, Inc. and affiliates.

'use client';

/**
* @file page.tsx
* @input None
* @output A bare page with a DropdownMenu in a fixed top bar and one in the
* content of a page that scrolls with the document
* @position A raw page, with no sandbox chrome, for checking on a phone how a
* menu opens under a finger. The menu in the fixed bar opens as the finger
* presses. The menu in the content waits for the content-touch delay, so a
* flick that starts on it scrolls the page.
*/

import {useState} from 'react';
import * as stylex from '@stylexjs/stylex';
import {
DropdownMenu,
type DropdownMenuOption,
} from '@astryxdesign/core/DropdownMenu';
import {HStack, VStack} from '@astryxdesign/core/Layout';
import {Heading, Text} from '@astryxdesign/core/Text';
import {colorVars, spacingVars} from '@astryxdesign/core/theme/tokens.stylex';

const styles = stylex.create({
// A fixed bar: a trigger under a fixed ancestor is not in a scroll view.
bar: {
position: 'fixed',
insetBlockStart: 0,
insetInlineStart: 0,
insetInlineEnd: 0,
zIndex: 1,
paddingBlock: spacingVars['--spacing-2'],
paddingInline: spacingVars['--spacing-4'],
backgroundColor: colorVars['--color-background-body'],
},
content: {
paddingBlockStart: spacingVars['--spacing-12'],
},
});

const ROW_COUNT = 40;

export default function MenuPressCasesPage() {
const [ran, setRan] = useState<string[]>([]);
const run = (label: string) => () => setRan(previous => [...previous, label]);
const items = (prefix: string): DropdownMenuOption[] =>
['Edit', 'Duplicate', 'Share'].map(label => ({
label,
onClick: run(`${prefix}: ${label}`),
}));
const last = ran.at(-1);
const lastCount = ran.filter(entry => entry === last).length;

return (
<VStack gap={6} padding={4} xstyle={styles.content}>
<HStack justify="between" align="center" xstyle={styles.bar}>
<DropdownMenu button={{label: 'Actions'}} items={items('Actions')} />
<Text color="secondary" aria-live="polite">
{last == null ? 'Nothing ran yet' : `Ran ${last} (${lastCount}×)`}
</Text>
</HStack>
<VStack gap={1}>
<Heading level={1}>Menu press cases</Heading>
<Text color="secondary">
Under a finger, Actions in the fixed bar opens as the finger touches
it. Press it, slide to Duplicate and lift: Duplicate runs once.
</Text>
<Text color="secondary">
More, below, sits in the page, which scrolls. It opens after a short
beat, so a flick that starts on it scrolls the page instead.
</Text>
</VStack>
<DropdownMenu button={{label: 'More'}} items={items('More')} />
{Array.from({length: ROW_COUNT}, (_, index) => (
<Text key={index}>
Row {index + 1}: text that makes the page taller than the screen.
</Text>
))}
</VStack>
);
}
6 changes: 6 additions & 0 deletions apps/sandbox/src/app/sandboxPages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ export const categories: SandboxCategory[] = [
description:
'An alert over a toast and a dialog closed after a save, on a page that scrolls with the document, to check on a phone',
},
{
name: 'Menu Press Cases',
href: '/pages/menu-press-cases/',
description:
'A DropdownMenu in a fixed top bar that opens as a finger presses it, and one in the content, on a page that scrolls with the document',
},
{
name: 'BottomSheet Pull',
href: '/pages/bottom-sheet-pull/',
Expand Down
Loading