Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
4076bf3
spec(AST-094): touch presentations follow UIKit
vjeux Oct 24, 2026
4dc2aae
feat(core): one touch presentation resolver
vjeux Oct 24, 2026
9d2d720
feat(core): the touch presentation resolver knows the iOS idiom
vjeux Oct 24, 2026
7065daf
fix(core): one touch model on every device; the adaptive change is a …
cixzhang Oct 24, 2026
92ef66c
Merge main into wip/uikit-pr-touch-presentation
cixzhang Oct 24, 2026
398c723
fix(core): the touch resolver reads the theme's compact definition
cixzhang Oct 24, 2026
33ee284
docs(MoreMenu): keep the doc's own formatting; change only the compac…
cixzhang Oct 24, 2026
1264c5b
fix(core): compact follows the active theme's md; the branch drops it…
cixzhang Oct 24, 2026
ec08340
docs(spec): drop this branch's stacked copy of AST-094
cixzhang Oct 24, 2026
ced7766
docs(ContextMenu, MoreMenu): the compact edge is the theme md breakpoint
cixzhang Oct 25, 2026
4d728a7
refactor(core): drop the unused isCompactTouch from the touch present…
vjeux Oct 25, 2026
d34d800
test(core): the adaptive menu's compact edges in Chromium and WebKit
vjeux Oct 25, 2026
c5efd27
Merge main into #8062 (lab typecheck fix aa3b92f320 and current main)
vjeux Oct 25, 2026
b8642ba
test(core): the touch presentation's browser proofs leave for the des…
vjeux Oct 25, 2026
f809dae
test(DropdownMenu): a sub-menu's drill-in follows a theme that moves md
vjeux Oct 25, 2026
4b5e872
refactor(core): readTouchPresentation takes the compact definition it…
vjeux Oct 25, 2026
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/touch-presentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@astryxdesign/core': patch
---

[feat] `presentation="adaptive"` on DropdownMenu, ContextMenu, MoreMenu, Selector and MultiSelector, and a DropdownMenu's or ContextMenu's default sub-menu drill-in, now use the theme's compact definition with a coarse primary pointer: a viewport narrower than the theme's `md` point (768px by default) or shorter than 500px. This is a behavior change. The old default was a bottom sheet at 768px wide and below on a coarse pointer. Now a coarse-pointer screen exactly 768px wide keeps the anchored popover, and a phone in landscape (wider than 768px but shorter than 500px) gets the bottom sheet and the drilled-in sub-menu. A theme that moves `md` moves the edge with it. To pin a component's presentation regardless of the rule, pass `presentation="popover"` or `presentation="bottom-sheet"`; to keep a sub-menu's flyout, pass `presentation="flyout"` on `DropdownMenuSubMenu`. Mouse and keyboard users on desktop see no change, because every case requires a coarse pointer.

@vjeux
2 changes: 1 addition & 1 deletion apps/storybook/stories/ContextMenu.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ export const AdaptivePresentation: Story = {
docs: {
description: {
story:
'Uses the built-in adaptive policy: BottomSheet at 768px and below with a coarse primary pointer, cursor-positioned popover otherwise. Important actions still need a visible MoreMenu or equivalent entry point.',
'Uses the built-in adaptive policy: BottomSheet on a compact touch screen (a coarse primary pointer, and a viewport narrower than the theme `md` breakpoint (768px by default) or shorter than 500px), cursor-positioned popover otherwise. Important actions still need a visible MoreMenu or equivalent entry point.',
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion apps/storybook/stories/MoreMenu.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ export const AdaptivePresentation: Story = {
docs: {
description: {
story:
'Uses the built-in adaptive policy: BottomSheet at 768px and below with a coarse primary pointer, anchored popover otherwise. Use device emulation to exercise the touch branch.',
'Uses the built-in adaptive policy: BottomSheet on a compact touch screen (a coarse primary pointer, and a viewport narrower than the theme `md` breakpoint (768px by default) or shorter than 500px), anchored popover otherwise. Use device emulation to exercise the touch branch.',
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/ContextMenu/ContextMenu.doc.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export const docs = {
name: 'presentation',
type: "'popover' | 'bottom-sheet' | 'adaptive'",
description:
'Presentation policy. `popover` opens at the pointer position, `bottom-sheet` always uses an action sheet, and `adaptive` uses the BottomSheet at 768px and below when the primary pointer is coarse.',
'Presentation policy. `popover` opens at the pointer position, `bottom-sheet` always uses an action sheet, and `adaptive` uses the BottomSheet on a compact touch screen: a coarse primary pointer, and a viewport narrower than the theme `md` breakpoint (768px by default) or shorter than 500px.',
default: "'popover'",
},
{
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/ContextMenu/ContextMenu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {DropdownMenuSubMenu} from '../DropdownMenu/DropdownMenuSubMenu';
import {Divider} from '../Divider';
import {useLayerDismissal} from '../Layer/useLayerDismissal';
import {warmMenuBottomSheet} from '../DropdownMenu/__tests__/warmMenuBottomSheet';
import {COMPACT_TOUCH_PRESENTATION_QUERY} from '../hooks/useAdaptivePresentation';

// The touch sheet is loaded lazily; resolve its modules once up front, so
// ContextMenu's own lazy sheet renders within the cases' waitFor.
Expand Down Expand Up @@ -309,7 +310,7 @@ describe('ContextMenu', () => {
vi.stubGlobal(
'matchMedia',
vi.fn().mockImplementation((query: string) => ({
matches: query === '(max-width: 768px) and (pointer: coarse)',
matches: query === COMPACT_TOUCH_PRESENTATION_QUERY,
media: query,
onchange: null,
addEventListener: vi.fn(),
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/DropdownMenu/DropdownMenu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {rtlStyles} from '../utils';
import {__resetInteractionModalityForTest} from '../utils/interactionModality';
import {focusOutlineStyles} from '../utils/focusOutline.stylex';
import {spacingVars} from '../theme/tokens.stylex';
import {COMPACT_TOUCH_PRESENTATION_QUERY} from '../hooks/useAdaptivePresentation';

// Mock showPopover and hidePopover methods since they're not implemented in jsdom
beforeEach(() => {
Expand Down Expand Up @@ -341,7 +342,7 @@ describe('DropdownMenu', () => {
vi.stubGlobal(
'matchMedia',
vi.fn().mockImplementation((query: string) => ({
matches: query === '(max-width: 768px) and (pointer: coarse)',
matches: query === COMPACT_TOUCH_PRESENTATION_QUERY,
media: query,
onchange: null,
addEventListener: vi.fn(),
Expand Down
57 changes: 57 additions & 0 deletions packages/core/src/DropdownMenu/DropdownMenuSubMenu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {warmMenuBottomSheet} from './__tests__/warmMenuBottomSheet';
import {IconButton} from '../IconButton';
import {RadioList, RadioListItem} from '../RadioList';
import {COMPACT_TOUCH_PRESENTATION_QUERY} from '../hooks/useAdaptivePresentation';
import {Theme, defineTheme} from '../theme';
import {rtlStyles} from '../utils';

beforeEach(() => {
Expand Down Expand Up @@ -1455,6 +1456,62 @@ describe('DropdownMenuSubMenu drill-in on a phone', () => {
await waitFor(() => shownRow('Back to Actions'));
});

it("follows the theme's md point: a 900 px touch screen drills in under md 1000, and keeps the flyout under the default (spec:AST-012 FR9)", async () => {
// A query-aware stand-in for a 900 × 1024 coarse-pointer screen: `,` is
// or, `and` is and.
const screenSize = {width: 900, height: 1024};
vi.stubGlobal(
'matchMedia',
vi.fn().mockImplementation((query: string) => ({
matches: query.split(', ').some(alternative =>
alternative.split(' and ').every(part => {
if (part === '(pointer: coarse)') {
return true;
}
const range = /^\((width|height) < (\d+)px\)$/.exec(part);
return (
range != null &&
screenSize[range[1] as 'width' | 'height'] < Number(range[2])
);
}),
),
media: query,
onchange: null,
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
addListener: vi.fn(),
removeListener: vi.fn(),
dispatchEvent: vi.fn(),
})),
);
const wideMd = defineTheme({
name: 'wide-md-drill-in',
adaptations: {widthBreakpoints: {md: 1000, lg: 1100}},
});
const user = userEvent.setup();
const menu = (
<DropdownMenu button={{label: 'Actions'}}>
<DropdownMenuSubMenu label="Move to">
<DropdownMenuItem label="Folder A" onClick={() => {}} />
</DropdownMenuSubMenu>
</DropdownMenu>
);
// The default md point (768): not compact, so the sub-menu flies out.
const {unmount} = render(menu);
await user.click(screen.getByRole('button', {name: /Actions/}));
fireEvent.click(await waitFor(() => shownRow('Move to')), {detail: 1});
const flyout = await waitFor(() => shownMenu('Move to'));
expect(flyout.closest('[popover]')).not.toBe(
shownMenu('Actions').closest('[popover]'),
);
unmount();
// A theme whose md is 1000: the same screen is compact, and it drills in.
render(<Theme theme={wideMd}>{menu}</Theme>);
await user.click(screen.getByRole('button', {name: /Actions/}));
fireEvent.click(await waitFor(() => shownRow('Move to')), {detail: 1});
await waitFor(() => shownRow('Back to Actions'));
});

it('closing the menu resets the drilled view', async () => {
stubCompactTouch(true);
const user = userEvent.setup();
Expand Down
12 changes: 7 additions & 5 deletions packages/core/src/DropdownMenu/useMenuDrillIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,21 @@
import {useCallback, useMemo, useState, type ReactNode} from 'react';
import * as stylex from '@stylexjs/stylex';
import type {DropdownMenuDrillIn} from './DropdownMenuContext';
import {COMPACT_TOUCH_PRESENTATION_QUERY} from '../hooks/useAdaptivePresentation';
import {useCompactDefinition} from '../utils/touchPresentation';

/**
* The same query the root presentation uses to decide the bottom sheet, so
* The same compact-touch condition the root presentation uses to decide the
* bottom sheet (the active theme's, spec:AST-012 FR9), so
* one component carries one meaning of "adaptive". A bare `(pointer: coarse)`
* would disagree with it on a large touch tablet: the menu would stay an
* anchored popover while its sub-menus replaced rows in place, a combination
* nobody designed.
*/
function matchesCompactTouch(): boolean {
function matchesCompactTouch(query: string): boolean {
return (
typeof window !== 'undefined' &&
typeof window.matchMedia === 'function' &&
window.matchMedia(COMPACT_TOUCH_PRESENTATION_QUERY).matches
window.matchMedia(query).matches
);
}

Expand Down Expand Up @@ -70,6 +71,7 @@ export interface UseMenuDrillInReturn {
* opens and the stack empties when it closes.
*/
export function useMenuDrillIn(isOpen: boolean): UseMenuDrillInReturn {
const compactTouchQuery = useCompactDefinition().coarsePointerQuery;

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.

No test pins this theme read: replacing it with DEFAULT_COMPACT_DEFINITION.coarsePointerQuery leaves the touch-presentation, DropdownMenu, DropdownMenuSubMenu and ContextMenu suites green, while the same swap in useAdaptivePresentation fails the md: 1000 case. One sub-menu case under that theme would keep the drill-in and the root sheet from drifting apart.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Pinned in f809dae. On a 900 px coarse-pointer screen, the sub-menu flies out under the default md (768) and drills in under a theme whose md is 1000. Replacing the theme read with DEFAULT_COMPACT_DEFINITION.coarsePointerQuery makes the test fail.

const [isCompactTouch, setIsCompactTouch] = useState(false);
const [viewStack, setViewStack] = useState<ReadonlyArray<string>>([]);
const [host, setHost] = useState<HTMLElement | null>(null);
Expand All @@ -81,7 +83,7 @@ export function useMenuDrillIn(isOpen: boolean): UseMenuDrillInReturn {
if (wasOpen !== isOpen) {
setWasOpen(isOpen);
if (isOpen) {
setIsCompactTouch(matchesCompactTouch());
setIsCompactTouch(matchesCompactTouch(compactTouchQuery));
} else if (viewStack.length > 0) {
setViewStack([]);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/MoreMenu/MoreMenu.doc.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export const docs = {
{
name: 'presentation',
type: "'popover' | 'bottom-sheet' | 'adaptive'",
description: 'Presentation policy forwarded to DropdownMenu. `adaptive` keeps the anchored popover on pointer-based layouts and uses a BottomSheet at 768px and below when the primary pointer is coarse.',
description: 'Presentation policy forwarded to DropdownMenu. `adaptive` keeps the anchored popover on pointer-based layouts and uses a BottomSheet on a compact touch screen: a coarse primary pointer, and a viewport narrower than the theme `md` breakpoint (768px by default) or shorter than 500px.',
default: "'popover'",
},
{
Expand Down Expand Up @@ -204,7 +204,7 @@ export const docsZh = {
{
name: 'presentation',
type: "'popover' | 'bottom-sheet' | 'adaptive'",
description: '菜单呈现策略。`adaptive` 在指针布局中使用锚定浮层,在主指针为粗略指针且宽度不超过 768px 时使用 BottomSheet。',
description: '菜单呈现策略。`adaptive` 在指针布局中使用锚定浮层,在主指针为粗略指针且视口宽度小于主题的 `md` 断点(默认 768px)或高度小于 500px 时使用 BottomSheet。',
default: "'popover'",
},
{
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/MultiSelector/MultiSelector.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {selectorPresentationStyles} from '../Selector/selectorPresentation.style
import {groupStyles} from '../InputGroup/groupStyles';
import {InputGroup, InputGroupText} from '../InputGroup';
import {colorVars, focusVars} from '../theme/tokens.stylex';
import {COMPACT_TOUCH_PRESENTATION_QUERY} from '../hooks/useAdaptivePresentation';

/**
* Enters a search query as one change. Typing it key by key can land several
Expand Down Expand Up @@ -160,7 +161,7 @@ describe('MultiSelector', () => {
vi.stubGlobal(
'matchMedia',
vi.fn().mockImplementation((query: string) => ({
matches: query === '(max-width: 768px) and (pointer: coarse)',
matches: query === COMPACT_TOUCH_PRESENTATION_QUERY,
media: query,
onchange: null,
addEventListener: vi.fn(),
Expand Down Expand Up @@ -2197,7 +2198,7 @@ describe('MultiSelector', () => {
vi.mocked(matchMedia).mockImplementation(
(query: string) =>
({
matches: query === '(max-width: 768px) and (pointer: coarse)',
matches: query === COMPACT_TOUCH_PRESENTATION_QUERY,
media: query,
onchange: null,
addEventListener: vi.fn(),
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/Selector/Selector.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {generateThemeCSS} from '../theme/generateThemeRules';
import {colorVars, spacingVars} from '../theme/tokens.stylex';
import {selectorPresentationStyles} from './selectorPresentation.stylex';
import {groupStyles} from '../InputGroup/groupStyles';
import {COMPACT_TOUCH_PRESENTATION_QUERY} from '../hooks/useAdaptivePresentation';

/**
* Enters a search query as one change. Typing it key by key can land several
Expand Down Expand Up @@ -392,7 +393,7 @@ describe('Selector', () => {
vi.stubGlobal(
'matchMedia',
vi.fn().mockImplementation((query: string) => ({
matches: query === '(max-width: 768px) and (pointer: coarse)',
matches: query === COMPACT_TOUCH_PRESENTATION_QUERY,
media: query,
onchange: null,
addEventListener: vi.fn(),
Expand Down Expand Up @@ -2831,7 +2832,7 @@ describe('Selector', () => {
vi.mocked(matchMedia).mockImplementation(
(query: string) =>
({
matches: query === '(max-width: 768px) and (pointer: coarse)',
matches: query === COMPACT_TOUCH_PRESENTATION_QUERY,
media: query,
onchange: null,
addEventListener: vi.fn(),
Expand Down
21 changes: 14 additions & 7 deletions packages/core/src/hooks/useAdaptivePresentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@

/**
* @file useAdaptivePresentation.ts
* @input Uses the shared SSR-safe media-query hook
* @input Uses the shared SSR-safe media-query hook and the touch
* presentation's compact-touch query
* @output Resolves popover/bottom-sheet presentation policy
* @position Internal overlay policy shared across component families
*/

import {
COMPACT_TOUCH_QUERY,
useCompactDefinition,
} from '../utils/touchPresentation';
import {useMediaQuery} from './useMediaQuery';

export type AdaptivePresentation = 'popover' | 'bottom-sheet' | 'adaptive';
Expand All @@ -17,16 +22,18 @@ export type ResolvedAdaptivePresentation = Exclude<
'adaptive'
>;

// Width keeps desktop-class tablets and large touch displays anchored by
// default. Pointer capability, rather than `hover: none`, avoids excluding
// touch browsers that also report hover capability.
export const COMPACT_TOUCH_PRESENTATION_QUERY =
'(max-width: 768px) and (pointer: coarse)';
// A sheet needs both a compact viewport and a coarse primary pointer: tablets
// and large touch displays stay anchored, phones in either orientation get
// the sheet. Compact is the active theme's definition (spec:AST-012 FR9);
// this constant is its value at the default width points.
export const COMPACT_TOUCH_PRESENTATION_QUERY = COMPACT_TOUCH_QUERY;

export function useAdaptivePresentation(
presentation: AdaptivePresentation,
): ResolvedAdaptivePresentation {
const isCompactTouch = useMediaQuery(COMPACT_TOUCH_PRESENTATION_QUERY);
const isCompactTouch = useMediaQuery(
useCompactDefinition().coarsePointerQuery,
);
return presentation === 'adaptive'
? isCompactTouch
? 'bottom-sheet'
Expand Down
Loading
Loading