diff --git a/src/components/common/input/CalcInput.jsx b/src/components/common/input/CalcInput.jsx index a92b86c7..6a26174d 100644 --- a/src/components/common/input/CalcInput.jsx +++ b/src/components/common/input/CalcInput.jsx @@ -77,7 +77,7 @@ export const CalculatorInput = forwardRef( newDisplayValue = calculator.currentOperand setDisplayValue(newDisplayValue) - onChange(newDisplayValue) + onChange?.(newDisplayValue) requestAnimationFrame(() => { if (inputRef.current) { @@ -145,7 +145,7 @@ export const CalculatorInput = forwardRef( newDisplayValue = calculator.currentOperand setDisplayValue(newDisplayValue) if (!hasOperation) { - onChange(calculator.currentOperand) + onChange?.(calculator.currentOperand) } } else if (num === '.') { if (!calculator.currentOperand.includes('.')) { @@ -153,7 +153,7 @@ export const CalculatorInput = forwardRef( newDisplayValue = calculator.currentOperand setDisplayValue(newDisplayValue) if (!hasOperation) { - onChange(newDisplayValue) + onChange?.(newDisplayValue) } } } else if (!shouldPreventInput(calculator.currentOperand)) { @@ -161,7 +161,7 @@ export const CalculatorInput = forwardRef( newDisplayValue = calculator.currentOperand setDisplayValue(newDisplayValue) if (!hasOperation) { - onChange(newDisplayValue) + onChange?.(newDisplayValue) } } // else { @@ -169,7 +169,7 @@ export const CalculatorInput = forwardRef( // newDisplayValue = calculator.currentOperand // setDisplayValue(newDisplayValue) // if (!hasOperation) { - // onChange(newDisplayValue) + // onChange?.(newDisplayValue) // } // } } @@ -236,7 +236,7 @@ export const CalculatorInput = forwardRef( const displayValue = newValue || '0' setDisplayValue(displayValue) setHasOperation(false) - onChange(displayValue) + onChange?.(displayValue) // 커서를 텍스트 끝으로 이동하고 스크롤 처리 requestAnimationFrame(() => { if (inputRef.current) { @@ -260,7 +260,7 @@ export const CalculatorInput = forwardRef( setDisplayValue(resultStr) setHasOperation(false) // Only call onChange with the final result - onChange(resultStr) + onChange?.(resultStr) // 엔터키로 호출된 경우 포커스 설정하지 않음 if (!fromEnterKey) { @@ -282,7 +282,7 @@ export const CalculatorInput = forwardRef( const displayValue = newValue || '0' setDisplayValue(displayValue) setHasOperation(!!calculator.operation) - onChange(displayValue) + onChange?.(displayValue) // 커서를 텍스트 끝으로 이동하고 스크롤 처리 requestAnimationFrame(() => { if (inputRef.current) { @@ -337,10 +337,10 @@ export const CalculatorInput = forwardRef( calculator.currentOperand = filteredValue setHasOperation(false) // 연산자가 없는 순수 숫자일 때만 부모 컴포넌트의 onChange 호출 - onChange(filteredValue) + onChange?.(filteredValue) } - //onChange(filteredValue) + //onChange?.(filteredValue) } } @@ -485,7 +485,7 @@ export const CalculatorInput = forwardRef( onClick={() => { // const newValue = calculatorRef.current.clear() // setDisplayValue(newValue || '0') - // onChange(newValue || '0') + // onChange?.(newValue || '0') handleClear() setHasOperation(false) }} @@ -497,7 +497,7 @@ export const CalculatorInput = forwardRef( onClick={() => { // const newValue = calculatorRef.current.deleteNumber() // setDisplayValue(newValue || '0') - // onChange(newValue || '0') + // onChange?.(newValue || '0') //setHasOperation(!!calculatorRef.current.operation) handleDelete() }} @@ -532,7 +532,7 @@ export const CalculatorInput = forwardRef(