diff --git a/src/client/AnchoredPopover.tsx b/src/client/AnchoredPopover.tsx index f45ec389..914d1d60 100644 --- a/src/client/AnchoredPopover.tsx +++ b/src/client/AnchoredPopover.tsx @@ -21,6 +21,7 @@ import { } from 'react' import { createPortal } from 'react-dom' import { createFrameBatcher } from './frame-batcher.ts' +import { useViewportInsetTop } from './viewport-inset.ts' /** The popover's default visual width (viewport-clamped). */ const POP_WIDTH = 264 @@ -62,6 +63,8 @@ export function AnchoredPopover(props: AnchoredPopoverProps): ReactNode { const baseRef = useRef({ left: 0, top: 0 }) const cardWidth = Math.min(width, window.innerWidth - VIEWPORT_MARGIN * 2) + /** The shell's native window-control band: pointer events die in it. */ + const topFloor = VIEWPORT_MARGIN + useViewportInsetTop() // Measure + position once the card is in the DOM (and whenever the anchor // or content changes size). layout effect: no visible jump. @@ -73,15 +76,18 @@ export function AnchoredPopover(props: AnchoredPopoverProps): ReactNode { const height = card.offsetHeight let top = rect.bottom + 6 if (top + height > window.innerHeight - VIEWPORT_MARGIN) { - top = Math.max(VIEWPORT_MARGIN, rect.top - height - 6) + top = Math.max(topFloor, rect.top - height - 6) } + // The anchor itself may sit in the band (a row near the top edge): opening + // just below it still leaves our own header under the native controls. + top = Math.max(topFloor, top) const left = Math.min( Math.max(VIEWPORT_MARGIN, rect.left), Math.max(VIEWPORT_MARGIN, window.innerWidth - cardWidth - VIEWPORT_MARGIN), ) baseRef.current = { left, top } setPos({ left: left + offsetRef.current.x, top: top + offsetRef.current.y }) - }, [anchor, children, cardWidth]) + }, [anchor, children, cardWidth, topFloor]) // A new anchor starts a fresh placement (never inherit another node's drag). useEffect(() => { setOffset({ x: 0, y: 0 }) }, [anchor]) @@ -103,8 +109,8 @@ export function AnchoredPopover(props: AnchoredPopoverProps): ReactNode { Math.max(VIEWPORT_MARGIN - base.left, window.innerWidth - cardWidth - VIEWPORT_MARGIN - base.left), ) const nextY = Math.min( - Math.max(start.y + (move.clientY - startY), VIEWPORT_MARGIN - base.top), - Math.max(VIEWPORT_MARGIN - base.top, window.innerHeight - 48 - base.top), + Math.max(start.y + (move.clientY - startY), topFloor - base.top), + Math.max(topFloor - base.top, window.innerHeight - 48 - base.top), ) pendingDragRef.current = { offset: { x: nextX, y: nextY }, @@ -127,7 +133,7 @@ export function AnchoredPopover(props: AnchoredPopoverProps): ReactNode { window.addEventListener('pointermove', onMove) window.addEventListener('pointerup', onUp) window.addEventListener('pointercancel', onUp) - }, [cardWidth, dragBatcher, draggable]) + }, [cardWidth, dragBatcher, draggable, topFloor]) // Global dismissal (see the file header for the contract). useEffect(() => {