diff --git a/frontend/src/components/Dropdown.tsx b/frontend/src/components/Dropdown.tsx index a6776f58..7dcaefc4 100644 --- a/frontend/src/components/Dropdown.tsx +++ b/frontend/src/components/Dropdown.tsx @@ -78,6 +78,7 @@ function Dropdown({ const searchRef = useRef(null); const [open, setOpen] = useState(false); const [query, setQuery] = useState(''); + const [dropUp, setDropUp] = useState(false); const radius = rounded === '3xl' ? 'rounded-3xl' : 'rounded-xl'; const radiusTop = rounded === '3xl' ? 'rounded-t-3xl' : 'rounded-t-xl'; @@ -90,14 +91,23 @@ function Dropdown({ setQuery(''); } }; - document.addEventListener('mousedown', handler); - return () => document.removeEventListener('mousedown', handler); + document.addEventListener('mousedown', handler, true); + return () => document.removeEventListener('mousedown', handler, true); }, []); useEffect(() => { if (open && searchable && searchRef.current) searchRef.current.focus(); }, [open, searchable]); + const handleToggle = () => { + if (!open && ref.current) { + const rect = ref.current.getBoundingClientRect(); + const spaceBelow = window.innerHeight - rect.bottom; + setDropUp(spaceBelow < 220); + } + setOpen((v) => !v); + }; + const filtered = useMemo(() => { if (!searchable || !query.trim()) return options; const q = query.toLowerCase(); @@ -110,8 +120,8 @@ function Dropdown({