diff --git a/ui/src/pages/Mappings.jsx b/ui/src/pages/Mappings.jsx index 1c5156d..1cc2d26 100644 --- a/ui/src/pages/Mappings.jsx +++ b/ui/src/pages/Mappings.jsx @@ -4,6 +4,7 @@ import { api, authHeaders } from '../api' function AutocompleteInput({ value, onChange, onEnter, suggestions = [], className, placeholder }) { const [open, setOpen] = useState(false) const [highlighted, setHighlighted] = useState(0) + const [dropPos, setDropPos] = useState(null) const inputRef = useRef() const listRef = useRef() @@ -12,6 +13,10 @@ function AutocompleteInput({ value, onChange, onEnter, suggestions = [], classNa : suggestions function openList() { + if (inputRef.current) { + const r = inputRef.current.getBoundingClientRect() + setDropPos({ top: r.bottom + 2, left: r.left, minWidth: r.width }) + } setOpen(true) setHighlighted(0) } @@ -42,7 +47,6 @@ function AutocompleteInput({ value, onChange, onEnter, suggestions = [], classNa if (e.key === 'Enter') onEnter?.() } - // Scroll highlighted item into view useEffect(() => { if (!open || !listRef.current) return const item = listRef.current.children[highlighted] @@ -60,10 +64,11 @@ function AutocompleteInput({ value, onChange, onEnter, suggestions = [], classNa onKeyDown={handleKeyDown} onBlur={e => { if (!listRef.current?.contains(e.relatedTarget)) setOpen(false) }} /> - {open && filtered.length > 0 && ( + {open && filtered.length > 0 && dropPos && (