|
26 | 26 | * touch model on every touch device) the popover opens and closes the way |
27 | 27 | * UIMenu does: it grows out of its trigger on UIKit's open spring and |
28 | 28 | * collapses back into it on the close spring (menuSurfaceMotion.ts), and a |
29 | | - * pan that begins outside closes it. Under a mouse it keeps the layer's own |
30 | | - * entrance and the theme's motion tokens (D-01). |
| 29 | + * pan that begins outside closes it. On a compact touch screen it also sits |
| 30 | + * where UIMenu does: over its trigger, centered on it, top-aligned |
| 31 | + * (bottom-aligned when the trigger is in the lower half of the viewport), |
| 32 | + * 8 px from the viewport's sides. Under a mouse it keeps the layer's own |
| 33 | + * entrance and placement and the theme's motion tokens (D-01). |
31 | 34 | * |
32 | 35 | * Initial focus on open follows the input modality: a keyboard open |
33 | 36 | * (Enter / Space / ArrowDown on the trigger) focuses the first enabled item |
@@ -89,8 +92,11 @@ import {resolveMenuWidth} from './menuWidth'; |
89 | 92 | import {layerViewportInset} from '../Layer/layerViewportInset.stylex'; |
90 | 93 | import type {AdaptivePresentation} from '../hooks/useAdaptivePresentation'; |
91 | 94 | import {usePresentation} from '../utils/presentation'; |
| 95 | +import {useTouchPresentation} from '../utils/touchPresentation'; |
92 | 96 | import { |
| 97 | + COVER_TRIGGER_STYLE, |
93 | 98 | createMenuSurfaceMotion, |
| 99 | + placeOverTrigger, |
94 | 100 | type MenuSurfaceMotion, |
95 | 101 | } from './DropdownMenuTouch'; |
96 | 102 | // Loaded on demand: only the bottom-sheet presentation renders the sheet. |
@@ -436,15 +442,19 @@ interface DropdownMenuBaseProps extends BaseProps { |
436 | 442 | hasChevron?: boolean; |
437 | 443 | /** |
438 | 444 | * Popover position relative to the trigger. Ignored by bottom-sheet |
439 | | - * presentation. |
| 445 | + * presentation, and on a compact touch screen under the touch modes (unless |
| 446 | + * `presentation` is `'popover'`), where the menu sits over its trigger as |
| 447 | + * UIMenu does. |
440 | 448 | * Uses the same placement values as other Astryx layer-based components. |
441 | 449 | * @default 'below' |
442 | 450 | */ |
443 | 451 | placement?: LayerPlacement; |
444 | 452 |
|
445 | 453 | /** |
446 | 454 | * Popover alignment along the placement axis. Ignored by bottom-sheet |
447 | | - * presentation. |
| 455 | + * presentation, and on a compact touch screen under the touch modes (unless |
| 456 | + * `presentation` is `'popover'`), where the menu is centered on its trigger |
| 457 | + * as UIMenu is. |
448 | 458 | * Uses the same alignment values as other Astryx layer-based components. |
449 | 459 | * @default 'start' |
450 | 460 | */ |
@@ -985,6 +995,15 @@ function DropdownMenuPopover({ |
985 | 995 | // motion and the pan-outside dismissal. |
986 | 996 | const isTouchPresentationRef = useRef(false); |
987 | 997 | const isUikitMotionRef = useRef(false); |
| 998 | + // On a compact touch screen, under the touch modes, the popover covers its |
| 999 | + // trigger as UIMenu does (iOS 26.2): centered on it, kept off the |
| 1000 | + // viewport's sides by CSS, with its vertical edge chosen as it opens |
| 1001 | + // (placeOverTrigger). Elsewhere, and with a pinned 'popover', it opens |
| 1002 | + // below it. |
| 1003 | + const {isCompactTouch} = useTouchPresentation(); |
| 1004 | + const coversTrigger = touchModes === true && isCompactTouch; |
| 1005 | + const coversTriggerRef = useRef(coversTrigger); |
| 1006 | + coversTriggerRef.current = coversTrigger; |
988 | 1007 | const getSurfaceMotion = useCallback( |
989 | 1008 | (element: HTMLElement): MenuSurfaceMotion => { |
990 | 1009 | const current = surfaceMotionRef.current; |
@@ -1136,6 +1155,7 @@ function DropdownMenuPopover({ |
1136 | 1155 | isUikitMotionRef.current = isUikitMotion; |
1137 | 1156 | const trigger = buttonRef.current; |
1138 | 1157 | if (surface != null && trigger != null) { |
| 1158 | + placeOverTrigger(surface, trigger, coversTriggerRef.current); |
1139 | 1159 | const motion = getSurfaceMotion(surface); |
1140 | 1160 | if (isUikitMotion) { |
1141 | 1161 | motion.enter(() => { |
@@ -1888,18 +1908,29 @@ function DropdownMenuPopover({ |
1888 | 1908 | </MenuRegionsContext> |
1889 | 1909 | </div>, |
1890 | 1910 | ), |
1891 | | - { |
1892 | | - placement, |
1893 | | - alignment, |
1894 | | - offset: spacingVars['--spacing-1'], |
1895 | | - xstyle: [ |
1896 | | - styles.popoverViewport, |
1897 | | - resolvedMaxHeight != null && |
1898 | | - dynamicStyles.popoverViewportMaxBlockSize(resolvedMaxHeight), |
1899 | | - popoverXstyle, |
1900 | | - layerAnimations[placement], |
1901 | | - ], |
1902 | | - }, |
| 1911 | + coversTrigger |
| 1912 | + ? { |
| 1913 | + positioning: 'custom', |
| 1914 | + style: COVER_TRIGGER_STYLE, |
| 1915 | + xstyle: [ |
| 1916 | + styles.popoverViewport, |
| 1917 | + resolvedMaxHeight != null && |
| 1918 | + dynamicStyles.popoverViewportMaxBlockSize(resolvedMaxHeight), |
| 1919 | + popoverXstyle, |
| 1920 | + ], |
| 1921 | + } |
| 1922 | + : { |
| 1923 | + placement, |
| 1924 | + alignment, |
| 1925 | + offset: spacingVars['--spacing-1'], |
| 1926 | + xstyle: [ |
| 1927 | + styles.popoverViewport, |
| 1928 | + resolvedMaxHeight != null && |
| 1929 | + dynamicStyles.popoverViewportMaxBlockSize(resolvedMaxHeight), |
| 1930 | + popoverXstyle, |
| 1931 | + layerAnimations[placement], |
| 1932 | + ], |
| 1933 | + }, |
1903 | 1934 | )} |
1904 | 1935 | </> |
1905 | 1936 | ); |
|
0 commit comments