Skip to content

Commit b385a54

Browse files
committed
Refocus the input on word skip
1 parent 0b0d827 commit b385a54

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

src/App.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { type ReactNode } from "react";
1+
import React, { type ReactNode, useRef } from "react";
22

33
import styles from "./App.module.css";
44
import Rounds from "./Rounds";
@@ -28,6 +28,8 @@ export default function App() {
2828
const [state, dispatch] = useAppState();
2929
useLoadData(dispatch);
3030

31+
const guessInputRef = useRef<HTMLInputElement | null>(null);
32+
3133
switch (state.phase) {
3234
case "pre-game": {
3335
if (state.wordPack == null) {
@@ -55,6 +57,7 @@ export default function App() {
5557
>
5658
<label className={`${styles.guessLabel} centered-container flex-col`}>
5759
<input
60+
ref={guessInputRef}
5861
type="text"
5962
autoFocus
6063
className={`${styles.guess} word`}
@@ -66,7 +69,12 @@ export default function App() {
6669
<div>Unscramble the word!</div>
6770
</label>
6871
<div className={`${styles.buttonRow} centered-container flex-row`}>
69-
<button onClick={() => dispatch({ type: "skip-word" })}>
72+
<button
73+
onClick={() => {
74+
dispatch({ type: "skip-word" });
75+
guessInputRef.current?.focus();
76+
}}
77+
>
7078
Skip
7179
</button>
7280
<button onClick={() => dispatch({ type: "end-game" })}>

0 commit comments

Comments
 (0)