Skip to content

Commit

Permalink
feat: 게임 입장 모달 인풋에 자동 포커스 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
zizonyoungjun committed Dec 2, 2024
1 parent 925029c commit ef669c7
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ReactDOM from 'react-dom';
import { useState, useEffect } from 'react';
import { useState, useEffect, useRef } from 'react';
import { Tooltip } from 'react-tooltip';

interface IGameEntryModalProps {
Expand All @@ -20,6 +20,7 @@ export default function GameEntryModal({
const [gameCode, setGameCode] = useState('');
const [errorMessage, setErrorMessage] = useState('');
const [showTooltip, setShowTooltip] = useState(false);
const inputRef = useRef<HTMLInputElement | null>(null);

useEffect(() => {
if (!localStorage.getItem('modalTooltipShown')) {
Expand All @@ -28,6 +29,10 @@ export default function GameEntryModal({
}
}, []);

useEffect(() => {
inputRef.current?.focus();
}, []);

const handleConfirm = () => {
if (gameCode.trim()) {
setErrorMessage('');
Expand Down Expand Up @@ -59,6 +64,7 @@ export default function GameEntryModal({
{textForm && (
<input
type="text"
ref={inputRef}
placeholder={textForm}
value={gameCode}
onChange={(e) => setGameCode(e.target.value)}
Expand Down

0 comments on commit ef669c7

Please sign in to comment.