rf: dom queries in UserMessage component

This commit is contained in:
Carlos Daniel Vilaseca 2024-03-03 17:33:01 -05:00
parent a5c1ac9680
commit 13f0052122

View file

@ -20,18 +20,17 @@
let edit = false; let edit = false;
let editedContent = ''; let editedContent = '';
let messageEditTextArea: HTMLTextAreaElement;
const editMessageHandler = async () => { const editMessageHandler = async () => {
edit = true; edit = true;
editedContent = message.content; editedContent = message.content;
await tick(); await tick();
const editElement = document.getElementById(`message-edit-${message.id}`);
editElement.style.height = ''; messageEditTextArea.style.height = '';
editElement.style.height = `${editElement.scrollHeight}px`; messageEditTextArea.style.height = `${messageEditTextArea.scrollHeight}px`;
editElement?.focus(); messageEditTextArea?.focus();
}; };
const editMessageConfirmHandler = async () => { const editMessageConfirmHandler = async () => {
@ -165,10 +164,11 @@
<div class=" w-full"> <div class=" w-full">
<textarea <textarea
id="message-edit-{message.id}" id="message-edit-{message.id}"
bind:this={messageEditTextArea}
class=" bg-transparent outline-none w-full resize-none" class=" bg-transparent outline-none w-full resize-none"
bind:value={editedContent} bind:value={editedContent}
on:input={(e) => { on:input={(e) => {
e.target.style.height = `${e.target.scrollHeight}px`; messageEditTextArea.style.height = `${messageEditTextArea.scrollHeight}px`;
}} }}
/> />