Skip to content

Commit

Permalink
feat: ゲーム開始直後のBoxへのフォーカスを実装
Browse files Browse the repository at this point in the history
  • Loading branch information
Tsuyopon-1067 committed Mar 28, 2024
1 parent 031a6e3 commit 8546348
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions typing-app/src/components/templates/GameTyping.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import RegisterScore, { ResultScore } from "@/types/RegisterScore";
import { Box } from "@chakra-ui/react";
import Image from "next/image";
import React, { useEffect, useState } from "react";
import React, { useEffect, useRef, useState } from "react";
import ProgressBar from "../atoms/ProgressBar";
import { GameTypingProps } from "../pages/Game";
import styles from "./GameTyping.module.css";
Expand Down Expand Up @@ -155,8 +155,16 @@ const GameTyping: React.FC<GameTypingProps> = ({ nextPage, filenames, setResultS
}
};

// ゲーム開始直後にフォーカスする
const boxRef = useRef<HTMLDivElement>(null);
useEffect(() => {
if (boxRef.current) {
boxRef.current.focus();
}
}, []);

return (
<Box onKeyDown={handleOnKeyDown} tabIndex={0}>
<Box onKeyDown={handleOnKeyDown} tabIndex={0} ref={boxRef}>
<div className={styles.box}>
<div className={`${styles.heading} ${styles.heading_name}`}>Article Name</div>
<div className={`${styles.heading} ${styles.heading_time}`}>Time Remain</div>
Expand Down

0 comments on commit 8546348

Please sign in to comment.