From 7beb1c84e7f9ba272ef5d72a55a4861d59964c12 Mon Sep 17 00:00:00 2001 From: Tiago Ribeiro Date: Tue, 20 Jun 2023 22:21:50 +0100 Subject: [PATCH] Solved a bug in WriteBlanks where it wasn't saving the user's answer --- src/components/Exercises/WriteBlanks.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/components/Exercises/WriteBlanks.tsx b/src/components/Exercises/WriteBlanks.tsx index bbbc6bd7..3351687f 100644 --- a/src/components/Exercises/WriteBlanks.tsx +++ b/src/components/Exercises/WriteBlanks.tsx @@ -12,6 +12,7 @@ import Button from "../Low/Button"; function Blank({ id, maxWords, + userSolution, showSolutions = false, setUserSolution, }: { @@ -20,9 +21,9 @@ function Blank({ userSolution?: string; maxWords: number; showSolutions?: boolean; - setUserSolution?: (solution: string) => void; + setUserSolution: (solution: string) => void; }) { - const [userInput, setUserInput] = useState(""); + const [userInput, setUserInput] = useState(userSolution || ""); useEffect(() => { const words = userInput.split(" ").filter((x) => x !== ""); @@ -37,6 +38,7 @@ function Blank({ className={clsx("input border rounded-xl px-2 py-1 bg-white text-blue-400 border-blue-400 my-2")} placeholder={id} onChange={(e) => setUserInput(e.target.value)} + onBlur={() => setUserSolution(userInput)} value={userInput} contentEditable={showSolutions} />