diff --git a/frontend/src/components/ChatBox/ChatBox.css b/frontend/src/components/ChatBox/ChatBox.css index aefad4ed4..f132fb247 100644 --- a/frontend/src/components/ChatBox/ChatBox.css +++ b/frontend/src/components/ChatBox/ChatBox.css @@ -1,34 +1,50 @@ #chat-box { display: flex; flex-direction: column; - flex-grow: 1; + justify-content: flex-end; + width: 100%; + height: 100%; } #chat-box-footer { display: flex; flex-direction: column; + width: 100%; font-size: 12px; padding: 32px; + box-sizing: border-box; } #chat-box-footer-messages { display: flex; flex-direction: row; - height: 52px; + align-items: flex-end; + width: 100%; } #chat-box-input { + text-align: left; + padding: 18px 12px; + width: 85%; + height: 100%; align-self: flex-end; justify-content: center; - flex-grow: 1; - height: 100%; - padding: 0 12px; box-sizing: border-box; + resize: none; + background-color: inherit; + + min-height: 53px; + overflow-y: auto; + + font-size: inherit; + font-family: inherit; + color: white; } #chat-box-button-send { + width: 15%; height: 100%; - width: 74px; + max-height: 53px; margin-left: 8px; } @@ -40,9 +56,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..497b0adc5 100644 --- a/frontend/src/components/ChatBox/ChatBox.tsx +++ b/frontend/src/components/ChatBox/ChatBox.tsx @@ -47,8 +47,35 @@ function ChatBox({ }); }, [setEmails]); - function inputKeyPressed(event: React.KeyboardEvent) { - if (event.key === "Enter") { + function inputChange() { + const inputBoxElement = document.getElementById( + "chat-box-input" + ) as HTMLSpanElement; + + // scroll to the bottom + inputBoxElement.scrollTop = + inputBoxElement.scrollHeight - inputBoxElement.clientHeight; + + const maxHeightPx = 150; + inputBoxElement.style.height = "0"; + if (inputBoxElement.scrollHeight > maxHeightPx) { + inputBoxElement.style.height = `${maxHeightPx}px`; + inputBoxElement.style.overflowY = "auto"; + } else { + inputBoxElement.style.height = `${inputBoxElement.scrollHeight}px`; + inputBoxElement.style.overflowY = "hidden"; + } + } + + function inputKeyDown(event: React.KeyboardEvent) { + if (event.key === "Enter" && !event.shiftKey) { + event.preventDefault(); + } + } + + function inputKeyUp(event: React.KeyboardEvent) { + // shift+enter shouldn't send message + if (event.key === "Enter" && !event.shiftKey) { // asynchronously send the message void sendChatMessage(); } @@ -57,7 +84,7 @@ function ChatBox({ async function sendChatMessage() { const inputBoxElement = document.getElementById( "chat-box-input" - ) as HTMLInputElement; + ) as HTMLTextAreaElement; // get the message from the input box const message = inputBoxElement.value; // clear the input box @@ -65,7 +92,6 @@ function ChatBox({ if (message && !isSendingMessage) { setIsSendingMessage(true); - // if input has been edited, add both messages to the list of messages. otherwise add original message only addChatMessage({ message: message, @@ -166,13 +192,15 @@ function ChatBox({