diff --git a/src/app/components/modal-overlay/ModalOverlay.test.tsx b/src/app/components/modal-overlay/ModalOverlay.test.tsx index 36713dd2c..d74936e52 100644 --- a/src/app/components/modal-overlay/ModalOverlay.test.tsx +++ b/src/app/components/modal-overlay/ModalOverlay.test.tsx @@ -47,6 +47,11 @@ vi.mock('folds', () => ({ {children} ), + Modal: ({ children, size }: any) => ( +
+ {children} +
+ ), Overlay: ({ open, backdrop, children }: any) => (
{backdrop}
@@ -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' }); diff --git a/src/app/components/modal-overlay/ModalOverlay.tsx b/src/app/components/modal-overlay/ModalOverlay.tsx index 857b80ec9..a473a182b 100644 --- a/src/app/components/modal-overlay/ModalOverlay.tsx +++ b/src/app/components/modal-overlay/ModalOverlay.tsx @@ -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['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 `` chrome. Callers passing `size` + * must not wrap children in `` themselves. */ + size?: ModalSize; /** The modal element, used as the focus fallback and as the fullscreen wrapper. */ contentRef?: MutableRefObject; /** 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(null); // Android back closes the overlay instead of navigating away. useDismissOnBack(requestClose, open); @@ -92,13 +99,20 @@ export function ModalOverlay({ contentRef?.current ?? document.body, + fallbackFocus: () => + (size ? ownedModalRef.current : contentRef?.current) ?? document.body, clickOutsideDeactivates: dismissOnClickOutside, onDeactivate: requestClose, escapeDeactivates, }} > - {children} + {size ? ( + + {children} + + ) : ( + children + )} diff --git a/src/app/features/room-settings/RoomSettingsRenderer.tsx b/src/app/features/room-settings/RoomSettingsRenderer.tsx index 67aa4d434..e66de208a 100644 --- a/src/app/features/room-settings/RoomSettingsRenderer.tsx +++ b/src/app/features/room-settings/RoomSettingsRenderer.tsx @@ -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(null); if (!room) return null; return ( - - - - - - - - + + + + + + ); } diff --git a/src/app/features/settings/SettingsShallowRouteRenderer.tsx b/src/app/features/settings/SettingsShallowRouteRenderer.tsx index dfcababc7..141e008fd 100644 --- a/src/app/features/settings/SettingsShallowRouteRenderer.tsx +++ b/src/app/features/settings/SettingsShallowRouteRenderer.tsx @@ -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(null); if (!routeMatch || !isShallowRoute(location.pathname, location.state, screenSize)) { return null; } return ( - - - - + + ); }