Skip to content

Commit eea3068

Browse files
committed
Merge the touch presentation resolver (#8062) under the TreeList expansion
2 parents 081b45a + 4dc2aae commit eea3068

12 files changed

Lines changed: 374 additions & 17 deletions

File tree

‎.changeset/touch-presentation.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] `presentation="adaptive"` on DropdownMenu, ContextMenu, MoreMenu, Selector and MultiSelector chooses the bottom sheet on a compact touch screen: a coarse primary pointer and a viewport narrower than 744px or shorter than 500px (it was 768px wide and below). An iPad mini in portrait keeps the anchored popover; a phone in landscape now gets the sheet.
6+
7+
@vjeux

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ export const AdaptivePresentation: Story = {
494494
docs: {
495495
description: {
496496
story:
497-
'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.',
497+
'Uses the built-in adaptive policy: BottomSheet on a compact touch screen (a coarse primary pointer, and a viewport narrower than 744px or shorter than 500px), cursor-positioned popover otherwise. Important actions still need a visible MoreMenu or equivalent entry point.',
498498
},
499499
},
500500
},

‎apps/storybook/stories/MoreMenu.stories.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ export const AdaptivePresentation: Story = {
316316
docs: {
317317
description: {
318318
story:
319-
'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.',
319+
'Uses the built-in adaptive policy: BottomSheet on a compact touch screen (a coarse primary pointer, and a viewport narrower than 744px or shorter than 500px), anchored popover otherwise. Use device emulation to exercise the touch branch.',
320320
},
321321
},
322322
},

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export const docs = {
132132
name: 'presentation',
133133
type: "'popover' | 'bottom-sheet' | 'adaptive'",
134134
description:
135-
'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.',
135+
'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 744px or shorter than 500px.',
136136
default: "'popover'",
137137
},
138138
{

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {DropdownMenuSubMenu} from '../DropdownMenu/DropdownMenuSubMenu';
2828
import {Divider} from '../Divider';
2929
import {useLayerDismissal} from '../Layer/useLayerDismissal';
3030
import {warmMenuBottomSheet} from '../DropdownMenu/__tests__/warmMenuBottomSheet';
31+
import {COMPACT_TOUCH_PRESENTATION_QUERY} from '../hooks/useAdaptivePresentation';
3132

3233
// The touch sheet is loaded lazily; resolve its modules once up front, so
3334
// ContextMenu's own lazy sheet renders within the cases' waitFor.
@@ -309,7 +310,7 @@ describe('ContextMenu', () => {
309310
vi.stubGlobal(
310311
'matchMedia',
311312
vi.fn().mockImplementation((query: string) => ({
312-
matches: query === '(max-width: 768px) and (pointer: coarse)',
313+
matches: query === COMPACT_TOUCH_PRESENTATION_QUERY,
313314
media: query,
314315
onchange: null,
315316
addEventListener: vi.fn(),

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {rtlStyles} from '../utils';
3434
import {__resetInteractionModalityForTest} from '../utils/interactionModality';
3535
import {focusOutlineStyles} from '../utils/focusOutline.stylex';
3636
import {spacingVars} from '../theme/tokens.stylex';
37+
import {COMPACT_TOUCH_PRESENTATION_QUERY} from '../hooks/useAdaptivePresentation';
3738

3839
// Mock showPopover and hidePopover methods since they're not implemented in jsdom
3940
beforeEach(() => {
@@ -341,7 +342,7 @@ describe('DropdownMenu', () => {
341342
vi.stubGlobal(
342343
'matchMedia',
343344
vi.fn().mockImplementation((query: string) => ({
344-
matches: query === '(max-width: 768px) and (pointer: coarse)',
345+
matches: query === COMPACT_TOUCH_PRESENTATION_QUERY,
345346
media: query,
346347
onchange: null,
347348
addEventListener: vi.fn(),

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export const docs = {
104104
{
105105
name: 'presentation',
106106
type: "'popover' | 'bottom-sheet' | 'adaptive'",
107-
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.',
107+
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 744px or shorter than 500px.',
108108
default: "'popover'",
109109
},
110110
{
@@ -204,7 +204,7 @@ export const docsZh = {
204204
{
205205
name: 'presentation',
206206
type: "'popover' | 'bottom-sheet' | 'adaptive'",
207-
description: '菜单呈现策略。`adaptive` 在指针布局中使用锚定浮层,在主指针为粗略指针且宽度不超过 768px 时使用 BottomSheet。',
207+
description: '菜单呈现策略。`adaptive` 在指针布局中使用锚定浮层,在主指针为粗略指针且视口宽度小于 744px 或高度小于 500px 时使用 BottomSheet。',
208208
default: "'popover'",
209209
},
210210
{

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {selectorPresentationStyles} from '../Selector/selectorPresentation.style
3636
import {groupStyles} from '../InputGroup/groupStyles';
3737
import {InputGroup, InputGroupText} from '../InputGroup';
3838
import {colorVars, focusVars} from '../theme/tokens.stylex';
39+
import {COMPACT_TOUCH_PRESENTATION_QUERY} from '../hooks/useAdaptivePresentation';
3940

4041
function generateThemeTestCSS(theme: Parameters<typeof generateThemeCSS>[0]) {
4142
const {prose, component} = generateThemeCSS(theme);
@@ -146,7 +147,7 @@ describe('MultiSelector', () => {
146147
vi.stubGlobal(
147148
'matchMedia',
148149
vi.fn().mockImplementation((query: string) => ({
149-
matches: query === '(max-width: 768px) and (pointer: coarse)',
150+
matches: query === COMPACT_TOUCH_PRESENTATION_QUERY,
150151
media: query,
151152
onchange: null,
152153
addEventListener: vi.fn(),
@@ -2183,7 +2184,7 @@ describe('MultiSelector', () => {
21832184
vi.mocked(matchMedia).mockImplementation(
21842185
(query: string) =>
21852186
({
2186-
matches: query === '(max-width: 768px) and (pointer: coarse)',
2187+
matches: query === COMPACT_TOUCH_PRESENTATION_QUERY,
21872188
media: query,
21882189
onchange: null,
21892190
addEventListener: vi.fn(),

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {generateThemeCSS} from '../theme/generateThemeRules';
3939
import {colorVars, spacingVars} from '../theme/tokens.stylex';
4040
import {selectorPresentationStyles} from './selectorPresentation.stylex';
4141
import {groupStyles} from '../InputGroup/groupStyles';
42+
import {COMPACT_TOUCH_PRESENTATION_QUERY} from '../hooks/useAdaptivePresentation';
4243

4344
function generateThemeTestCSS(theme: Parameters<typeof generateThemeCSS>[0]) {
4445
const {prose, component} = generateThemeCSS(theme);
@@ -378,7 +379,7 @@ describe('Selector', () => {
378379
vi.stubGlobal(
379380
'matchMedia',
380381
vi.fn().mockImplementation((query: string) => ({
381-
matches: query === '(max-width: 768px) and (pointer: coarse)',
382+
matches: query === COMPACT_TOUCH_PRESENTATION_QUERY,
382383
media: query,
383384
onchange: null,
384385
addEventListener: vi.fn(),
@@ -2817,7 +2818,7 @@ describe('Selector', () => {
28172818
vi.mocked(matchMedia).mockImplementation(
28182819
(query: string) =>
28192820
({
2820-
matches: query === '(max-width: 768px) and (pointer: coarse)',
2821+
matches: query === COMPACT_TOUCH_PRESENTATION_QUERY,
28212822
media: query,
28222823
onchange: null,
28232824
addEventListener: vi.fn(),

‎packages/core/src/hooks/useAdaptivePresentation.ts‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44

55
/**
66
* @file useAdaptivePresentation.ts
7-
* @input Uses the shared SSR-safe media-query hook
7+
* @input Uses the shared SSR-safe media-query hook and the touch
8+
* presentation's compact-touch query
89
* @output Resolves popover/bottom-sheet presentation policy
910
* @position Internal overlay policy shared across component families
1011
*/
1112

13+
import {COMPACT_TOUCH_QUERY} from '../utils/touchPresentation';
1214
import {useMediaQuery} from './useMediaQuery';
1315

1416
export type AdaptivePresentation = 'popover' | 'bottom-sheet' | 'adaptive';
@@ -17,11 +19,11 @@ export type ResolvedAdaptivePresentation = Exclude<
1719
'adaptive'
1820
>;
1921

20-
// Width keeps desktop-class tablets and large touch displays anchored by
21-
// default. Pointer capability, rather than `hover: none`, avoids excluding
22-
// touch browsers that also report hover capability.
23-
export const COMPACT_TOUCH_PRESENTATION_QUERY =
24-
'(max-width: 768px) and (pointer: coarse)';
22+
// A sheet needs both a compact viewport and a coarse primary pointer: tablets
23+
// and large touch displays stay anchored, phones in either orientation get
24+
// the sheet. The query is the shared touch presentation's
25+
// (utils/touchPresentation.ts).
26+
export const COMPACT_TOUCH_PRESENTATION_QUERY = COMPACT_TOUCH_QUERY;
2527

2628
export function useAdaptivePresentation(
2729
presentation: AdaptivePresentation,

0 commit comments

Comments
 (0)