Skip to content

Commit 4b5e872

Browse files
committed
refactor(core): readTouchPresentation takes the compact definition it reads
Its default ignored a theme that moves md; nothing calls it yet, so the compact definition is now required and its first caller passes the theme's (useCompactDefinition()). The changeset names ContextMenu's sub-menus, whose drill-in changes too.
1 parent f809dae commit 4b5e872

3 files changed

Lines changed: 9 additions & 7 deletions

File tree

‎.changeset/touch-presentation.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] `presentation="adaptive"` on DropdownMenu, ContextMenu, MoreMenu, Selector and MultiSelector, and a DropdownMenu'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.
5+
[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.
66

77
@vjeux

‎packages/core/src/utils/touchPresentation.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,11 @@ describe('touch presentation', () => {
171171

172172
it('reads the conditions at one moment, and without a window', () => {
173173
setDevice({coarse: true, width: 390, height: 844});
174-
expect(readTouchPresentation()).toEqual({
174+
expect(readTouchPresentation(window, DEFAULT_COMPACT_DEFINITION)).toEqual({
175175
isTouch: true,
176176
isCompact: true,
177177
});
178-
expect(readTouchPresentation(null)).toEqual({
178+
expect(readTouchPresentation(null, DEFAULT_COMPACT_DEFINITION)).toEqual({
179179
isTouch: false,
180180
isCompact: false,
181181
});

‎packages/core/src/utils/touchPresentation.ts‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,14 @@ export function useTouchPresentation(
135135

136136
/**
137137
* The touch presentation at this moment, for a decision taken once (a menu
138-
* deciding how it presents as it opens). Not touch and not compact where
139-
* there is no window.
138+
* deciding how it presents as it opens). `compact` is the active theme's
139+
* definition (`useCompactDefinition()`, read while rendering), required so a
140+
* theme that moves `md` is never ignored (spec:AST-012 FR9). Not touch and
141+
* not compact where there is no window.
140142
*/
141143
export function readTouchPresentation(
142-
view: Window | null = typeof window === 'undefined' ? null : window,
143-
compact: CompactDefinition = DEFAULT_COMPACT_DEFINITION,
144+
view: Window | null,
145+
compact: CompactDefinition,
144146
): TouchPresentation {
145147
if (view == null || typeof view.matchMedia !== 'function') {
146148
return {isTouch: false, isCompact: false};

0 commit comments

Comments
 (0)