From 7e3ef714827d2c64a75308455c854cc270579a71 Mon Sep 17 00:00:00 2001 From: yoosangwook Date: Tue, 7 Jan 2025 15:55:57 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=8Cfix:=20QSelectBox=20=EA=B8=B0?= =?UTF-8?q?=EB=B3=B8=EA=B0=92=20=EC=A1=B0=EA=B1=B4=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 컴포넌트 하나로 여러 탭에서 새용시 기본값 보여주는 로직 수정 --- src/components/common/select/QSelectBox.jsx | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/components/common/select/QSelectBox.jsx b/src/components/common/select/QSelectBox.jsx index 9f86474d..04a04aae 100644 --- a/src/components/common/select/QSelectBox.jsx +++ b/src/components/common/select/QSelectBox.jsx @@ -32,20 +32,16 @@ export default function QSelectBox({ * @returns {string} 초기 상태 */ const handleInitState = () => { - //title이 있으면 우선 보여준다(다른 키들 무시) - if (title !== '') { - return title - } - - //value가 없으면 showKey가 있으면 우선 보여준다 if (showKey !== '' && !value) { + //value가 없으면 showKey가 있으면 우선 보여준다 return options[0][showKey] - } - - //value가 있으면 sourceKey와 targetKey를 비교하여 보여준다 - if (showKey !== '' && value) { + } else if (showKey !== '' && value) { + //value가 있으면 sourceKey와 targetKey를 비교하여 보여준다 const option = options.find((option) => option[sourceKey] === value[targetKey]) return option[showKey] + } else { + //일치하는 조건이 없으면 기본값을 보여준다. + return title !== '' ? title : '선택하세요.' } }