From e5073085f7f4ccf7e16655112ae3895cda93e2e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=B3=B4=EA=B3=A4?= Date: Tue, 3 Feb 2026 10:16:43 +0900 Subject: [PATCH] =?UTF-8?q?fix:=EA=B3=84=EC=A0=95=EA=B3=BC=EB=AA=A9=20?= =?UTF-8?q?=ED=82=A4=EB=B3=B4=EB=93=9C=20=EB=84=A4=EB=B9=84=EA=B2=8C?= =?UTF-8?q?=EC=9D=B4=EC=85=98=20=EA=B0=9C=EC=84=A0=20-=20=ED=99=94?= =?UTF-8?q?=EC=82=B4=ED=91=9C=20=ED=82=A4=EB=A1=9C=20=EC=88=9C=ED=99=98=20?= =?UTF-8?q?=EC=84=A0=ED=83=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../views/barobill/eaccount/index.blade.php | 39 +++++++++++-------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/resources/views/barobill/eaccount/index.blade.php b/resources/views/barobill/eaccount/index.blade.php index 138b83b5..40f6deed 100644 --- a/resources/views/barobill/eaccount/index.blade.php +++ b/resources/views/barobill/eaccount/index.blade.php @@ -159,7 +159,7 @@ className={`px-2.5 py-1 rounded text-xs font-medium transition-colors ${ const AccountCodeSelect = ({ value, onChange, accountCodes }) => { const [isOpen, setIsOpen] = useState(false); const [search, setSearch] = useState(''); - const [highlightIndex, setHighlightIndex] = useState(0); + const [highlightIndex, setHighlightIndex] = useState(-1); const containerRef = useRef(null); const listRef = useRef(null); @@ -177,7 +177,7 @@ className={`px-2.5 py-1 rounded text-xs font-medium transition-colors ${ // 검색어 변경 시 하이라이트 초기화 useEffect(() => { - setHighlightIndex(0); + setHighlightIndex(-1); }, [search]); // 외부 클릭 시 닫기 @@ -186,7 +186,7 @@ className={`px-2.5 py-1 rounded text-xs font-medium transition-colors ${ if (containerRef.current && !containerRef.current.contains(e.target)) { setIsOpen(false); setSearch(''); - setHighlightIndex(0); + setHighlightIndex(-1); } }; document.addEventListener('mousedown', handleClickOutside); @@ -198,14 +198,14 @@ className={`px-2.5 py-1 rounded text-xs font-medium transition-colors ${ onChange(code.code, selected?.name || ''); setIsOpen(false); setSearch(''); - setHighlightIndex(0); + setHighlightIndex(-1); }; const handleClear = (e) => { e.stopPropagation(); onChange('', ''); setSearch(''); - setHighlightIndex(0); + setHighlightIndex(-1); }; // 키보드 네비게이션 @@ -214,26 +214,31 @@ className={`px-2.5 py-1 rounded text-xs font-medium transition-colors ${ if (e.key === 'ArrowDown') { e.preventDefault(); - setHighlightIndex(prev => Math.min(prev + 1, maxIndex)); + const newIndex = highlightIndex < maxIndex ? highlightIndex + 1 : 0; + setHighlightIndex(newIndex); // 스크롤 따라가기 - if (listRef.current) { - const item = listRef.current.children[Math.min(highlightIndex + 1, maxIndex)]; - item?.scrollIntoView({ block: 'nearest' }); - } + setTimeout(() => { + if (listRef.current && listRef.current.children[newIndex]) { + listRef.current.children[newIndex].scrollIntoView({ block: 'nearest' }); + } + }, 0); } else if (e.key === 'ArrowUp') { e.preventDefault(); - setHighlightIndex(prev => Math.max(prev - 1, 0)); - if (listRef.current) { - const item = listRef.current.children[Math.max(highlightIndex - 1, 0)]; - item?.scrollIntoView({ block: 'nearest' }); - } + const newIndex = highlightIndex > 0 ? highlightIndex - 1 : maxIndex; + setHighlightIndex(newIndex); + setTimeout(() => { + if (listRef.current && listRef.current.children[newIndex]) { + listRef.current.children[newIndex].scrollIntoView({ block: 'nearest' }); + } + }, 0); } else if (e.key === 'Enter' && filteredCodes.length > 0) { e.preventDefault(); - handleSelect(filteredCodes[highlightIndex]); + const selectIndex = highlightIndex >= 0 ? highlightIndex : 0; + handleSelect(filteredCodes[selectIndex]); } else if (e.key === 'Escape') { setIsOpen(false); setSearch(''); - setHighlightIndex(0); + setHighlightIndex(-1); } };