Fix: only register window click listener when dropdown is open

This commit is contained in:
Anil Matcha 2026-03-24 03:35:49 +05:30
commit 11f850abfc

View file

@ -317,10 +317,15 @@ export default function VideoStudio({ apiKey, onGenerationComplete, historyItems
// close dropdown on outside click
useEffect(() => {
const handler = () => setOpenDropdown(null);
if (!openDropdown) return;
const handler = (e) => {
const isInsideDropdown = [modelBtnRef, arBtnRef, durationBtnRef, resolutionBtnRef, qualityBtnRef, modeBtnRef]
.some(ref => ref.current && ref.current.contains(e.target));
if (!isInsideDropdown) setOpenDropdown(null);
};
window.addEventListener('click', handler);
return () => window.removeEventListener('click', handler);
}, []);
}, [openDropdown]);
// textarea auto-resize
const handlePromptInput = (e) => {