diff --git a/frontend/src/components/Dropdown.tsx b/frontend/src/components/Dropdown.tsx index 89fe3df92..17516aaab 100644 --- a/frontend/src/components/Dropdown.tsx +++ b/frontend/src/components/Dropdown.tsx @@ -42,9 +42,26 @@ function Dropdown({ onDelete?: (value: string) => void; placeholder?: string; }) { + const dropdownRef = React.useRef(null); const [isOpen, setIsOpen] = React.useState(false); const borderRadius = rounded === 'xl' ? 'rounded-xl' : 'rounded-3xl'; const borderTopRadius = rounded === 'xl' ? 'rounded-t-xl' : 'rounded-t-3xl'; + + const handleClickOutside = (event: MouseEvent) => { + if ( + dropdownRef.current && + !dropdownRef.current.contains(event.target as Node) + ) { + setIsOpen(false); + } + }; + + React.useEffect(() => { + document.addEventListener('mousedown', handleClickOutside); + return () => { + document.removeEventListener('mousedown', handleClickOutside); + }; + }, []); return (