From 5b41f2440414faea8b727efdf1d922dbbaf06072 Mon Sep 17 00:00:00 2001 From: "C. Fuhrman" Date: Thu, 27 Feb 2025 23:20:17 -0500 Subject: [PATCH] Return key submits form Fixes #262 --- client/src/pages/Student/JoinRoom/JoinRoom.tsx | 12 ++++++++++-- client/src/pages/Teacher/Login/Login.tsx | 15 ++++++++++----- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/client/src/pages/Student/JoinRoom/JoinRoom.tsx b/client/src/pages/Student/JoinRoom/JoinRoom.tsx index f0ac8d7..57ecc22 100644 --- a/client/src/pages/Student/JoinRoom/JoinRoom.tsx +++ b/client/src/pages/Student/JoinRoom/JoinRoom.tsx @@ -111,6 +111,12 @@ const JoinRoom: React.FC = () => { webSocketService.submitAnswer(answerData); }; + const handleReturnKey = (e: React.KeyboardEvent) => { + if (e.key === 'Enter') { + handleSocket(); + } + }; + if (isWaitingForTeacher) { return (
@@ -167,7 +173,8 @@ const JoinRoom: React.FC = () => { onChange={(e) => setRoomName(e.target.value)} placeholder="Numéro de la salle" sx={{ marginBottom: '1rem' }} - fullWidth + fullWidth={true} + onKeyDown={handleReturnKey} /> { onChange={(e) => setUsername(e.target.value)} placeholder="Nom d'utilisateur" sx={{ marginBottom: '1rem' }} - fullWidth + fullWidth={true} + onKeyDown={handleReturnKey} /> { }; + const handleKeyPress = (e: React.KeyboardEvent) => { + if (e.key === 'Enter') { + login(); + } + }; return ( { onChange={(e) => setEmail(e.target.value)} placeholder="Adresse courriel" sx={{ marginBottom: '1rem' }} - fullWidth + fullWidth={true} + onKeyDown={handleKeyPress} // Add this line as well /> { onChange={(e) => setPassword(e.target.value)} placeholder="Mot de passe" sx={{ marginBottom: '1rem' }} - fullWidth + fullWidth={true} + onKeyDown={handleKeyPress} // Add this line as well />