feat: improve text input
This commit is contained in:
parent
e48af8e172
commit
80726bbce9
2 changed files with 15 additions and 6 deletions
|
@ -15,7 +15,7 @@
|
||||||
<div class="chat" id="chatContainer">
|
<div class="chat" id="chatContainer">
|
||||||
</div>
|
</div>
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
<input type="text" id="userInput" placeholder="Type your message here..." class="outline-none">
|
<textarea type="text" id="userInput" placeholder="Type your message here..." class="outline-none"></textarea>
|
||||||
<button class="send-button" id="sendButton" >Send</button>
|
<button class="send-button" id="sendButton" >Send</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="typing-indicator" id="typingIndicator">
|
<div class="typing-indicator" id="typingIndicator">
|
||||||
|
|
|
@ -13,10 +13,18 @@ sendButton.addEventListener("click", () => {
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
promptInput.addEventListener("keyup", () => {
|
promptInput.addEventListener("input", () => {
|
||||||
handleKeyPress(event);
|
if (promptInput.value.split("\n").length == 1) {
|
||||||
}
|
promptInput.style.height = "2.5rem";
|
||||||
);
|
} else {
|
||||||
|
promptInput.style.height = "";
|
||||||
|
promptInput.style.height = promptInput.scrollHeight + "px";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
promptInput.addEventListener("keypress", () => {
|
||||||
|
handleKeyPress(event);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
async function sendMessage() {
|
async function sendMessage() {
|
||||||
|
@ -99,7 +107,8 @@ function hideTypingIndicator() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleKeyPress(event) {
|
function handleKeyPress(event) {
|
||||||
if (event.key === "Enter") {
|
if (event.key == "Enter" && !event.shiftKey) {
|
||||||
|
event.preventDefault();
|
||||||
sendMessage();
|
sendMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue