From 19a0b145b3079e34430138cafbef1c97e157e879 Mon Sep 17 00:00:00 2001 From: George Sproston Date: Tue, 12 Sep 2023 09:13:59 +0100 Subject: [PATCH 1/7] WIP: Changing input to textarea --- frontend/src/components/ChatBox/ChatBox.css | 26 ++++++++++++--------- frontend/src/components/ChatBox/ChatBox.tsx | 25 +++++++++++++++++--- 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/frontend/src/components/ChatBox/ChatBox.css b/frontend/src/components/ChatBox/ChatBox.css index aefad4ed4..0220004c8 100644 --- a/frontend/src/components/ChatBox/ChatBox.css +++ b/frontend/src/components/ChatBox/ChatBox.css @@ -1,7 +1,8 @@ #chat-box { display: flex; flex-direction: column; - flex-grow: 1; + justify-content: flex-end; + height: 100%; } #chat-box-footer { @@ -14,22 +15,31 @@ #chat-box-footer-messages { display: flex; flex-direction: row; - height: 52px; } #chat-box-input { - align-self: flex-end; - justify-content: center; flex-grow: 1; + padding: 18px 12px; + width: 100%; height: 100%; - padding: 0 12px; + align-self: flex-end; + justify-content: center; box-sizing: border-box; + resize: none; + background-color: inherit; + + /* must inherit as it's a textarea */ + font-family: inherit; + font-size: inherit; + color: white; } #chat-box-button-send { height: 100%; + max-height: 53px; width: 74px; margin-left: 8px; + margin-top: auto; } #chat-box-button-content { @@ -40,9 +50,3 @@ height: 40%; width: 100%; } - -#chat-box-button-reset { - height: 34px; - width: 100%; - margin-top: 10px; -} diff --git a/frontend/src/components/ChatBox/ChatBox.tsx b/frontend/src/components/ChatBox/ChatBox.tsx index ff0dd3c71..f895a4f33 100644 --- a/frontend/src/components/ChatBox/ChatBox.tsx +++ b/frontend/src/components/ChatBox/ChatBox.tsx @@ -47,7 +47,26 @@ function ChatBox({ }); }, [setEmails]); - function inputKeyPressed(event: React.KeyboardEvent) { + function resizeInputBox() { + // adjust the height of the text area + const maxHeight = 200; + const defaultHeight = 50; + const inputBoxElement = document.getElementById("chat-box-input") as + | HTMLTextAreaElement + | undefined; + if (inputBoxElement) { + if (inputBoxElement.scrollHeight > inputBoxElement.clientHeight) { + const newHeight = Math.min(inputBoxElement.scrollHeight, maxHeight); + inputBoxElement.style.height = "1px"; + inputBoxElement.style.height = `${newHeight}px`; + } else { + inputBoxElement.style.height = `${defaultHeight}px`; + } + } + } + + function inputKeyPressed(event: React.KeyboardEvent) { + resizeInputBox(); if (event.key === "Enter") { // asynchronously send the message void sendChatMessage(); @@ -166,12 +185,12 @@ function ChatBox({