Replies: 1 comment 1 reply
-
Yes! I also wanted this feature some time ago, and @huntabyte was actually open to receive a PR from me to add this feature. But unfortunately I wasn't able to solve it very elegantly so I didn't get it implemented in the end unfortunately. But the solutions in that article are relatively elegant. At least 10x more elegant than anything I was ever able to come up with. Unfortunately I just tried to implement it with tailwind like so: Click here to expand the code<script lang="ts">
import type { HTMLTextareaAttributes } from "svelte/elements";
import { cn } from "$lib/utils";
type $$Props = HTMLTextareaAttributes & {
["auto_grow"]?: boolean
};
let className: $$Props["class"] = undefined;
let autoGrow: $$Props["auto_grow"] = false;
export let value: $$Props["value"] = undefined;
export { className as class, autoGrow as auto_grow };
const baseClasses = " min-h-[80px] w-full rounded-md border border-input bg-transparent px-3 py-2 text-sm ring-offset-background"
</script>
<div data-replicated-value="{value ?? ""} " class={autoGrow
? `grid after:row-start-1 after:col-start-1 after:row-end-2 after:col-end-2 after:invisible after:whitespace-pre-wrap after:content-[attr(data-replicated-value)] ${baseClasses.split(" ").join(" after:")}`
: "contents"
}>
<textarea
class={cn(
"flex placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
baseClasses,
autoGrow ? "inline-block resize-none overflow-hidden row-start-1 col-start-1 row-end-2 col-end-2" : "",
className
)}
bind:value
on:blur
on:change
on:click
on:focus
on:keydown
on:keypress
on:keyup
on:mouseover
on:mouseenter
on:mouseleave
on:paste
on:input
{...$$restProps}
/>
</div> As you can see, I tried to use a constant called |
Beta Was this translation helpful? Give feedback.
-
It would be nice to make the textarea component have the option to auto expand when typing up to a specific max height limit.
This is a requirement that I come across a lot.
This article has a good example at the bottom on how to implement it now.
Article
It can also be solved with a on:input event listener.
Beta Was this translation helpful? Give feedback.
All reactions