From 881b2ddbf6ca26df1838e7dcbc6cd5bf843612c1 Mon Sep 17 00:00:00 2001 From: Assunta DeSanto Date: Tue, 19 Nov 2024 20:39:26 -0500 Subject: [PATCH] adding onClick event for submit button, adding keyDown functionality for enter button in input field, removing mouseUp/mouseDown, as it complicated the onClick event --- frontend/src/components/Footer/Footer.tsx | 28 +++++++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/frontend/src/components/Footer/Footer.tsx b/frontend/src/components/Footer/Footer.tsx index 6a60e3e9..e64e5183 100644 --- a/frontend/src/components/Footer/Footer.tsx +++ b/frontend/src/components/Footer/Footer.tsx @@ -1,14 +1,30 @@ // Footer.js -import { useState } from "react"; +import { useState, useRef, KeyboardEvent } from "react"; import { Link } from "react-router-dom"; import "../../App.css"; // Import the common Tailwind CSS styles function Footer() { const [isPressed, setIsPressed] = useState(false); + const emailInputRef =useRef(null); - const handleMouseDown = () => setIsPressed(true); - const handleMouseUp = () => setIsPressed(false); + const handleKeyDown = (event:KeyboardEvent) => { + if (event.key === 'Enter') { + event.preventDefault(); + document.getElementById('submitButton')?.click(); + } + }; + + //TODO - actually add email addresses to a mailing list, when available. for now, just logging in console, then clearing the input. + const handleSubmit = () => { + const email = emailInputRef.current?.value; + if (email){ + setIsPressed(true) //TODO - any async function that would require us to display "Loading..." + console.log(email); + emailInputRef.current.value = ''; + setIsPressed(false) + } + } return ( //
@@ -58,19 +74,21 @@ function Footer() {