fix(mobile): fill screen for room and space settings dialog

This commit is contained in:
Erwan Leboucher committed 2026-07-27 11:57:24 +02:00
1 parent 35694effdd
commit da1f50bf39
4 files changed
+47 -21

No files matched your search

@@ -47,6 +47,11 @@ vi.mock('folds', () => ({
{children}
</div>
),
Modal: ({ children, size }: any) => (
<div data-testid="modal" data-size={size}>
{children}
</div>
),
Overlay: ({ open, backdrop, children }: any) => (
<div data-testid="overlay" data-open={String(!!open)}>
<div data-testid="overlay-backdrop">{backdrop}</div>
@@ -205,6 +210,23 @@ describe('ModalOverlay', () => {
expect(screen.getByTestId('modal-child')).toBeInTheDocument();
});
it('wraps children in a Modal on desktop when size is set', () => {
desktop({ size: '500' });
const modal = screen.getByTestId('modal');
expect(modal).toHaveAttribute('data-size', '500');
expect(modal).toContainElement(screen.getByTestId('modal-child'));
});
it('does NOT wrap children in a Modal on mobile fullscreen when size is set (fills viewport)', () => {
mobile({ mobile: 'fullscreen', size: '500' });
// Regression (#1410): the fullscreen path must render children bare.
expect(screen.queryByTestId('modal')).not.toBeInTheDocument();
expect(screen.getByTestId('modal-child')).toBeInTheDocument();
expect(screen.getByTestId('focus-trap')).toBeInTheDocument();
});
it('renders sheet via MobileSwipeDownModal on mobile when mobile="sheet"', () => {
mobile({ mobile: 'sheet' });
@@ -1,6 +1,7 @@
import { useRef } from 'react';
import type { ComponentProps, MutableRefObject, ReactNode } from 'react';
import FocusTrap from 'focus-trap-react';
import { Box, Overlay, OverlayBackdrop, OverlayCenter } from 'folds';
import { Box, Modal, Overlay, OverlayBackdrop, OverlayCenter } from 'folds';
import { ScreenSize, useScreenSizeOptionally } from '$hooks/useScreenSize';
import { stopPropagation } from '$utils/keyboard';
import { useDismissOnBack } from '$utils/androidBack';
@@ -8,6 +9,7 @@ import { MobileSwipeDownModal } from '$components/MobileSwipeDownModal';
import * as messageCss from '$features/room/message/styles.css';
type FocusTrapOptions = ComponentProps<typeof FocusTrap>['focusTrapOptions'];
type ModalSize = '300' | '400' | '500';
type ModalOverlayProps = {
open?: boolean;
@@ -18,6 +20,9 @@ type ModalOverlayProps = {
* `fullscreen` drops the centred modal and fills the viewport.
* `sheet` rises as a bottom sheet with a swipe-down-to-dismiss handle. */
mobile?: 'centred' | 'fullscreen' | 'sheet';
/** When set, ModalOverlay owns the `<Modal>` chrome. Callers passing `size`
* must not wrap children in `<Modal>` themselves. */
size?: ModalSize;
/** The modal element, used as the focus fallback and as the fullscreen wrapper. */
contentRef?: MutableRefObject<HTMLDivElement | null>;
/** Set false for flows that Escape must not abort, such as device verification. */
@@ -30,12 +35,14 @@ export function ModalOverlay({
requestClose,
dismissOnClickOutside = true,
mobile = 'centred',
size,
contentRef,
escapeDeactivates = stopPropagation,
children,
}: ModalOverlayProps) {
// Null outside a provider, where desktop is the safe assumption.
const isMobile = useScreenSizeOptionally() === ScreenSize.Mobile;
const ownedModalRef = useRef<HTMLDivElement | null>(null);
// Android back closes the overlay instead of navigating away.
useDismissOnBack(requestClose, open);
@@ -92,13 +99,20 @@ export function ModalOverlay({
<FocusTrap
focusTrapOptions={{
initialFocus: false,
fallbackFocus: () => contentRef?.current ?? document.body,
fallbackFocus: () =>
(size ? ownedModalRef.current : contentRef?.current) ?? document.body,
clickOutsideDeactivates: dismissOnClickOutside,
onDeactivate: requestClose,
escapeDeactivates,
}}
>
{children}
{size ? (
<Modal ref={ownedModalRef} tabIndex={-1} size={size} variant="Background">
{children}
</Modal>
) : (
children
)}
</FocusTrap>
</OverlayCenter>
</Overlay>
@@ -1,5 +1,3 @@
import { useRef } from 'react';
import { Modal } from 'folds';
import { ModalOverlay } from '$components/modal-overlay/ModalOverlay';
import { useCloseRoomSettings, useRoomSettingsState } from '$state/hooks/roomSettings';
import { useAllJoinedRoomsSet, useGetRoom } from '$hooks/useGetRoom';
@@ -18,19 +16,16 @@ function RenderSettings({ state }: RenderSettingsProps) {
const getRoom = useGetRoom(allJoinedRooms);
const room = getRoom(roomId);
const space = spaceId && spaceId !== roomId ? getRoom(spaceId) : undefined;
const modalRef = useRef<HTMLDivElement | null>(null);
if (!room) return null;
return (
<ModalOverlay requestClose={closeSettings} mobile="fullscreen" contentRef={modalRef}>
<Modal ref={modalRef} tabIndex={-1} size="500" variant="Background">
<SpaceProvider value={space ?? null}>
<RoomProvider value={room}>
<RoomSettings initialPage={page} requestClose={closeSettings} />
</RoomProvider>
</SpaceProvider>
</Modal>
<ModalOverlay requestClose={closeSettings} mobile="fullscreen" size="500">
<SpaceProvider value={space ?? null}>
<RoomProvider value={room}>
<RoomSettings initialPage={page} requestClose={closeSettings} />
</RoomProvider>
</SpaceProvider>
</ModalOverlay>
);
}
@@ -1,6 +1,4 @@
import { useRef } from 'react';
import { matchPath, useLocation } from 'react-router-dom';
import { Modal } from 'folds';
import { useScreenSizeContext } from '$hooks/useScreenSize';
import { ModalOverlay } from '$components/modal-overlay/ModalOverlay';
import { isShallowRoute } from '$pages/client/shallowRoute';
@@ -13,17 +11,14 @@ export function SettingsShallowRouteRenderer() {
const screenSize = useScreenSizeContext();
const requestClose = useCloseShallowRoute();
const routeMatch = matchPath(SETTINGS_PATH, location.pathname);
const modalRef = useRef<HTMLDivElement | null>(null);
if (!routeMatch || !isShallowRoute(location.pathname, location.state, screenSize)) {
return null;
}
return (
<ModalOverlay requestClose={requestClose} mobile="fullscreen" contentRef={modalRef}>
<Modal ref={modalRef} tabIndex={-1} size="500" variant="Background">
<SettingsRoute routeSection={routeMatch.params.section} />
</Modal>
<ModalOverlay requestClose={requestClose} mobile="fullscreen" size="500">
<SettingsRoute routeSection={routeMatch.params.section} />
</ModalOverlay>
);
}