diff --git a/resources/views/barobill/hometax/index.blade.php b/resources/views/barobill/hometax/index.blade.php index e8d3c9b9..d4a2925c 100644 --- a/resources/views/barobill/hometax/index.blade.php +++ b/resources/views/barobill/hometax/index.blade.php @@ -1679,13 +1679,13 @@ className="px-4 py-2 text-sm font-medium text-white bg-violet-600 rounded-lg hov const partnerSearchRef = useRef(null); const partnerSearchTimerRef = useRef(null); const partnerSearchInputRef = useRef(null); + const partnerSearchBtnRef = useRef(null); // 검색 팝업 열기/닫기 const openPartnerSearch = () => { setShowPartnerSearch(true); setPartnerSearchQuery(''); setPartnerSearchResults(tradingPartners || []); - setTimeout(() => partnerSearchInputRef.current?.focus(), 50); }; const closePartnerSearch = () => { setShowPartnerSearch(false); @@ -1693,11 +1693,39 @@ className="px-4 py-2 text-sm font-medium text-white bg-violet-600 rounded-lg hov setPartnerSearchResults([]); }; - // 검색 팝업 외부 클릭 감지 + // 검색 팝업 위치 계산 + 포커스 + 외부 클릭 useEffect(() => { if (!showPartnerSearch) return; + // 위치 계산 + const positionPopup = () => { + if (!partnerSearchBtnRef.current || !partnerSearchRef.current) return; + const btnRect = partnerSearchBtnRef.current.getBoundingClientRect(); + const popup = partnerSearchRef.current; + const popupW = 420, popupMaxH = 360, gap = 6; + // 가로: 버튼 오른쪽 끝 기준 정렬 + let left = btnRect.right - popupW; + if (left < 8) left = 8; + if (left + popupW > window.innerWidth - 8) left = window.innerWidth - popupW - 8; + popup.style.left = left + 'px'; + // 세로: 아래 공간 우선, 부족하면 위로 + const spaceBelow = window.innerHeight - btnRect.bottom - gap; + const spaceAbove = btnRect.top - gap; + if (spaceBelow >= popupMaxH || spaceBelow >= spaceAbove) { + popup.style.top = (btnRect.bottom + gap) + 'px'; + popup.style.bottom = 'auto'; + } else { + popup.style.top = 'auto'; + popup.style.bottom = (window.innerHeight - btnRect.top + gap) + 'px'; + } + }; + requestAnimationFrame(() => { + positionPopup(); + partnerSearchInputRef.current?.focus(); + }); + // 외부 클릭 const handleClickOutside = (e) => { - if (partnerSearchRef.current && !partnerSearchRef.current.contains(e.target)) { + if (partnerSearchRef.current && !partnerSearchRef.current.contains(e.target) + && partnerSearchBtnRef.current && !partnerSearchBtnRef.current.contains(e.target)) { closePartnerSearch(); } }; @@ -1847,7 +1875,7 @@ className="px-3 py-1.5 bg-violet-100 text-violet-700 rounded-lg text-xs font-med {/* 등록번호 + 종사업장번호 */}