fix(mobile): treat tablets as compact for touch menus

This commit is contained in:
Erwan Leboucher committed 2026-08-03 15:41:34 +02:00
1 parent 18884554fa
commit afca2142a2
4 files changed
+10 -3

No files matched your search

+2 -3
View File
@@ -2,7 +2,7 @@ import type { ComponentProps, CSSProperties, ReactNode } from 'react';
import type { RectCords } from 'folds';
import { Box, Overlay, OverlayBackdrop, OverlayCenter, PopOut } from 'folds';
import FocusTrap from 'focus-trap-react';
import { ScreenSize, useScreenSizeOptionally } from '$hooks/useScreenSize';
import { useCompactLayout } from '$hooks/useScreenSize';
import { stopPropagation } from '$utils/keyboard';
import { useDismissOnBack } from '$utils/androidBack';
import { MobileSheetFocusTrap, MobileSwipeDownModal } from './MobileSwipeDownModal';
@@ -76,8 +76,7 @@ export function ResponsiveMenu({
mobile = 'sheet',
surfaceColor,
}: ResponsiveMenuProps) {
// Null outside a provider, where desktop is the safe assumption.
const isMobile = useScreenSizeOptionally() === ScreenSize.Mobile;
const isMobile = useCompactLayout();
const isKeyForward = (evt: KeyboardEvent) =>
evt.key === 'ArrowDown' || (arrowNavigation === 'both' && evt.key === 'ArrowRight');
@@ -63,6 +63,7 @@ vi.mock('$hooks/useScreenSize', () => ({
ScreenSize: { Desktop: 'Desktop', Tablet: 'Tablet', Mobile: 'Mobile' },
useScreenSizeContext: () => (screenMocks.isMobile ? 'Mobile' : 'Desktop'),
useScreenSizeOptionally: () => (screenMocks.isMobile ? 'Mobile' : 'Desktop'),
useCompactLayout: () => screenMocks.isMobile,
}));
const renderViewer = (props: { alt?: string; src?: string; info?: IImageInfo } = {}) =>
@@ -7,6 +7,7 @@ const screenMocks = vi.hoisted(() => ({ isMobile: true, tauri: false }));
vi.mock('$hooks/useScreenSize', () => ({
ScreenSize: { Desktop: 'Desktop', Tablet: 'Tablet', Mobile: 'Mobile' },
useScreenSizeOptionally: () => (screenMocks.isMobile ? 'Mobile' : 'Desktop'),
useCompactLayout: () => screenMocks.isMobile,
}));
vi.mock('@tauri-apps/api/core', () => ({
+6
View File
@@ -40,3 +40,9 @@ export const useScreenSizeContext = (): ScreenSize => {
}
return screenSize;
};
/** Tablet as well as Mobile, for touch presentation rather than available width. */
export const useCompactLayout = (): boolean => {
const screenSize = useContext(ScreenSizeContext);
return screenSize !== null && screenSize !== ScreenSize.Desktop;
};