fix: [journal] 거래처 드롭다운 클릭 시 즉시 닫히는 버그 수정
- onFocus에서 열린 경우 onClick 토글을 건너뛰도록 justFocusedRef 플래그 추가 - 다른 요소에서 포커스 이동 후 클릭 시 정상 동작
This commit is contained in:
@@ -583,6 +583,7 @@ className="px-4 py-2 text-sm font-medium text-white bg-emerald-600 rounded-lg ho
|
||||
};
|
||||
|
||||
const skipAutoOpenRef = useRef(false);
|
||||
const justFocusedRef = useRef(false);
|
||||
|
||||
const handleSelect = (partner) => {
|
||||
onChange(partner.id, partner.name);
|
||||
@@ -622,10 +623,14 @@ className="px-4 py-2 text-sm font-medium text-white bg-emerald-600 rounded-lg ho
|
||||
return (
|
||||
<div ref={containerRef} className="relative">
|
||||
<div ref={triggerRef} id={triggerId} tabIndex={0}
|
||||
onClick={() => { if (!isOpen) calcDropdownPos(); setIsOpen(!isOpen); }}
|
||||
onClick={() => {
|
||||
if (justFocusedRef.current) { justFocusedRef.current = false; return; }
|
||||
if (!isOpen) calcDropdownPos();
|
||||
setIsOpen(!isOpen);
|
||||
}}
|
||||
onFocus={() => {
|
||||
if (skipAutoOpenRef.current) { skipAutoOpenRef.current = false; return; }
|
||||
if (!isOpen) { calcDropdownPos(); setIsOpen(true); }
|
||||
if (!isOpen) { justFocusedRef.current = true; calcDropdownPos(); setIsOpen(true); }
|
||||
}}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Tab') {
|
||||
|
||||
Reference in New Issue
Block a user