All files / src/components EnterRoom.tsx

84.61% Statements 11/13
75% Branches 3/4
83.33% Functions 5/6
91.66% Lines 11/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55                    9x   9x   1x           9x   9x 2x     9x 1x     9x 3x     9x                                        
import React, {useState} from 'react';
import {Button} from 'antd';
 
interface EnterRoomProps {
  inputPlaceHolder: string;
  buttonText: string;
  enterRoomButtonClick: (arg0: string) => void;
}
 
function EnterRoom(props: EnterRoomProps): JSX.Element {
  const [roomId, setRoomId] = useState('');
  const element: JSX.Element = (
    <>
      <br />
      <Button id="button" onClick={() => props.enterRoomButtonClick(roomId)}>
        {props.buttonText}
      </Button>
    </>
  );
 
  const [focus, setFocus] = useState(0);
 
  const onFocus = () => {
    setFocus(1);
  };
 
  const onBlur = (e: React.FocusEvent<HTMLInputElement>) => {
    Iif (e.target.value === '') setFocus(0);
  };
 
  const inputOnchange = (e: React.ChangeEvent<HTMLInputElement>) => {
    setRoomId(e.target.value);
  };
 
  return (
    <div>
      또는
      <br />
      <form onSubmit={() => props.enterRoomButtonClick(roomId)}>
        <input
          className="input"
          onFocus={onFocus}
          onBlur={onBlur}
          placeholder={props.inputPlaceHolder} //코드(RoomId)를 입력해주세요.
          value={roomId}
          onChange={inputOnchange}
        />
        {focus ? element : null}
      </form>
    </div>
  );
}
 
export default EnterRoom;