계산기패드 초기화안되는 문제
This commit is contained in:
parent
a128b0b5bb
commit
72e4aded51
@ -11,9 +11,44 @@ export default function OuterLineWall({ props }) {
|
|||||||
|
|
||||||
const { length1, setLength1, length1Ref, arrow1, setArrow1 } = props
|
const { length1, setLength1, length1Ref, arrow1, setArrow1 } = props
|
||||||
|
|
||||||
|
const resetCalculatorValue = () => {
|
||||||
|
// 1. 즉시 상태를 0으로 변경
|
||||||
|
setLength1(0);
|
||||||
|
|
||||||
|
if (length1Ref.current) {
|
||||||
|
// 2. input에 포커스를 주어 계산기 UI가 떠있는 상태를 유지하게 함
|
||||||
|
length1Ref.current.focus();
|
||||||
|
length1Ref.current.value = '';
|
||||||
|
|
||||||
|
// 3. 약간의 시간차를 두어 계산기 UI 내부의 버튼을 찾음
|
||||||
|
setTimeout(() => {
|
||||||
|
const acButton = document.querySelector('.keypad-btn.ac, .btn-ac') ||
|
||||||
|
Array.from(document.querySelectorAll('button')).find(el => el.textContent === 'AC');
|
||||||
|
|
||||||
|
if (acButton) {
|
||||||
|
acButton.click();
|
||||||
|
} else {
|
||||||
|
// 버튼을 못 찾으면 강제로 input 이벤트와 Enter/Escape 등을 시뮬레이션
|
||||||
|
length1Ref.current.dispatchEvent(new Event('input', { bubbles: true }));
|
||||||
|
}
|
||||||
|
// 다시 포커스를 주어 키패드가 유지되도록 함 (필요시)
|
||||||
|
length1Ref.current.focus();
|
||||||
|
}, 10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 키보드 입력 처리
|
// 키보드 입력 처리
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleKeyDown = (e) => {
|
const handleKeyDown = (e) => {
|
||||||
|
|
||||||
|
if (['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'].includes(e.key)) {
|
||||||
|
// 계산기 값이 확정된 후 초기화하기 위해 약간의 지연을 줌
|
||||||
|
setTimeout(() => {
|
||||||
|
resetCalculatorValue();
|
||||||
|
}, 0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// 계산기 키패드가 보이는지 확인
|
// 계산기 키패드가 보이는지 확인
|
||||||
const keypadVisible = document.querySelector('.keypad-container')
|
const keypadVisible = document.querySelector('.keypad-container')
|
||||||
|
|
||||||
@ -88,37 +123,58 @@ export default function OuterLineWall({ props }) {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<button className="reset-btn" onClick={() => setLength1(0)}></button>
|
<button
|
||||||
|
className="reset-btn"
|
||||||
|
onClick={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
|
||||||
|
resetCalculatorValue()
|
||||||
|
}}
|
||||||
|
></button>
|
||||||
</div>
|
</div>
|
||||||
<div className="outline-form">
|
<div className="outline-form">
|
||||||
<span>{getMessage('modal.cover.outline.arrow')}</span>
|
<span>{getMessage('modal.cover.outline.arrow')}</span>
|
||||||
<div className="grid-direction">
|
<div className="grid-direction">
|
||||||
<button
|
<button
|
||||||
className={`direction up ${arrow1 === '↑' ? 'act' : ''}`}
|
className={`direction up ${arrow1 === '↑' ? 'act' : ''}`}
|
||||||
onClick={() => {
|
onClick={(e) => {
|
||||||
|
|
||||||
setArrow1('↑')
|
setArrow1('↑')
|
||||||
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowUp' }))
|
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowUp' }))
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
resetCalculatorValue()
|
||||||
}}
|
}}
|
||||||
></button>
|
></button>
|
||||||
<button
|
<button
|
||||||
className={`direction down ${arrow1 === '↓' ? 'act' : ''}`}
|
className={`direction down ${arrow1 === '↓' ? 'act' : ''}`}
|
||||||
onClick={() => {
|
onClick={(e) => {
|
||||||
setArrow1('↓')
|
setArrow1('↓')
|
||||||
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowDown' }))
|
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowDown' }))
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
resetCalculatorValue()
|
||||||
}}
|
}}
|
||||||
></button>
|
></button>
|
||||||
<button
|
<button
|
||||||
className={`direction left ${arrow1 === '←' ? 'act' : ''}`}
|
className={`direction left ${arrow1 === '←' ? 'act' : ''}`}
|
||||||
onClick={() => {
|
onClick={(e) => {
|
||||||
setArrow1('←')
|
setArrow1('←')
|
||||||
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowLeft' }))
|
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowLeft' }))
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
resetCalculatorValue()
|
||||||
}}
|
}}
|
||||||
></button>
|
></button>
|
||||||
<button
|
<button
|
||||||
className={`direction right ${arrow1 === '→' ? 'act' : ''}`}
|
className={`direction right ${arrow1 === '→' ? 'act' : ''}`}
|
||||||
onClick={() => {
|
onClick={(e) => {
|
||||||
setArrow1('→')
|
setArrow1('→')
|
||||||
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowRight' }))
|
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowRight' }))
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
resetCalculatorValue()
|
||||||
}}
|
}}
|
||||||
></button>
|
></button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user