Skip to content

Commit

Permalink
add auto_resize logic to textarea
Browse files Browse the repository at this point in the history
  • Loading branch information
nwaughachukwuma committed Dec 7, 2024
1 parent cc1141a commit 1270122
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions app/src/lib/components/ChatBoxAndWidget.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@
if (!searchTerm.trim()) return;
dispatch('submitSearch', { value: searchTerm });
}
function auto_resize(element: EventTarget & HTMLTextAreaElement) {
requestAnimationFrame(() => {
element.style.height = 'auto';
element.style.height = element.scrollHeight + 'px';
});
}
</script>

<div class="flex flex-col items-center max-lg:pt-16 md:justify-center h-full">
Expand All @@ -51,13 +58,13 @@
<div class="flex-1">
<textarea
placeholder="Message Audiora"
class="w-full outline-none bg-transparent border-0 focus:ring-0 text-white placeholder-zinc-400 resize-none py-3 px-4"
rows={1}
tabindex={0}
class="w-full outline-none bg-transparent border-0 focus:ring-0 text-white placeholder-zinc-400 resize-none py-3 px-4 max-h-72 overflow-hidden box-border"
rows="1"
autofocus
on:input={(e) => auto_resize(e.currentTarget)}
bind:value={searchTerm}
on:keypress={handleKeyPress}
/>
></textarea>
</div>
</div>
<div class="flex flex-row-reverse items-center justify-between p-2 bg-zinc-800/30">
Expand Down

0 comments on commit 1270122

Please sign in to comment.