diff --git a/CLAUDE.md b/CLAUDE.md index c02d57e..0b2e826 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -75,6 +75,7 @@ The constitution (`.specify/memory/constitution.md`) governs all feature work: - TypeScript 5.8 (strict mode, verbatimModuleSyntax) + React 19, Tailwind CSS v4 + React 19, Tailwind CSS v4, Vite 6 (022-fixed-layout-bars) - N/A (no storage changes -- purely presentational) (022-fixed-layout-bars) - Browser localStorage (existing adapter, updated to handle empty encounters) (023-clear-encounter) +- N/A (no storage changes — purely presentational fix) (024-fix-hp-popover-overflow) ## Recent Changes - 003-remove-combatant: Added TypeScript 5.x (strict mode, verbatimModuleSyntax) + React 19, Vite diff --git a/apps/web/src/components/hp-adjust-popover.tsx b/apps/web/src/components/hp-adjust-popover.tsx index 17c8642..bf0db78 100644 --- a/apps/web/src/components/hp-adjust-popover.tsx +++ b/apps/web/src/components/hp-adjust-popover.tsx @@ -1,5 +1,11 @@ import { Heart, Sword } from "lucide-react"; -import { useCallback, useEffect, useRef, useState } from "react"; +import { + useCallback, + useEffect, + useLayoutEffect, + useRef, + useState, +} from "react"; import { Button } from "./ui/button"; import { Input } from "./ui/input"; @@ -10,9 +16,28 @@ interface HpAdjustPopoverProps { export function HpAdjustPopover({ onAdjust, onClose }: HpAdjustPopoverProps) { const [inputValue, setInputValue] = useState(""); + const [pos, setPos] = useState<{ top: number; left: number } | null>(null); const ref = useRef(null); const inputRef = useRef(null); + useLayoutEffect(() => { + const el = ref.current; + if (!el) return; + const parent = el.parentElement; + if (!parent) return; + const trigger = parent.getBoundingClientRect(); + const popover = el.getBoundingClientRect(); + const vw = document.documentElement.clientWidth; + let left = trigger.left; + if (left + popover.width > vw) { + left = vw - popover.width - 8; + } + if (left < 8) { + left = 8; + } + setPos({ top: trigger.bottom + 4, left }); + }, []); + useEffect(() => { requestAnimationFrame(() => inputRef.current?.focus()); }, []); @@ -61,7 +86,12 @@ export function HpAdjustPopover({ onAdjust, onClose }: HpAdjustPopoverProps) { return (