diff --git a/src/components/form.jsx b/src/components/form.jsx index 65078e7..f298b1e 100644 --- a/src/components/form.jsx +++ b/src/components/form.jsx @@ -1,4 +1,4 @@ -import { useEffect, useRef, useState } from "react"; +import { useCallback, useEffect, useRef, useState } from "react"; import { LoadingSpinner } from "./loadingSpinner"; import copyImage from "../assets/copy.png"; const searchParams = new URLSearchParams(window.location.search); @@ -14,6 +14,7 @@ const Form = () => { const previousUserInput = useRef(undefined); const hasUserInputChanged = previousUserInput.current !== userInput; const [isCopied, setIsCopied] = useState(false); + const userInputRef = useRef(null); function clearDataBeforeFetch() { setErrorMessage(""); @@ -92,6 +93,21 @@ const Form = () => { } }, [isUserInputBlank]); + const handleClearInput = useCallback(() => { + setUserInput(""); + userInputRef.current?.focus(); + }, []); + + const hadleKeyDownOnClear = useCallback( + (e) => { + if (e.keyCode === 13) { + handleClearInput(); + e.preventDefault(); + } + }, + [handleClearInput] + ); + return (
@@ -112,7 +128,7 @@ const Form = () => {
-
+
{