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 : '선택하세요.' } }