Textarea
Grows with its text and counts what's left.
Variants
12 more takes on the textarea, each a single file you install on its own by its id.
aui-001Labelled
Label, hint and a live character count.
$ pnpm dlx asta-ui@latest add textarea-aui-001aui-002Auto-grow
Eases taller as you type, between a min and max.
$ pnpm dlx asta-ui@latest add textarea-aui-002aui-003Chat composer
Message box with attachment chips. ⌘ Enter sends.
$ pnpm dlx asta-ui@latest add textarea-aui-003aui-004Floating label
The label floats up on focus. Pure CSS.
$ pnpm dlx asta-ui@latest add textarea-aui-004aui-005Markdown toolbar
Markdown toolbar with shortcuts and a word count.
$ pnpm dlx asta-ui@latest add textarea-aui-005aui-006Mentions & commands
Type @ to mention and / for commands.
$ pnpm dlx asta-ui@latest add textarea-aui-006aui-007Validation
Rules checked on blur, ticked off live.
$ pnpm dlx asta-ui@latest add textarea-aui-007aui-008AI prompt box
Model picker, token count and Generate that turns into Stop. Needs radix-ui@base-ui/react.
$ pnpm dlx asta-ui@latest add textarea-aui-008 --radixaui-035Character budget
A character budget that warns near the end.
$ pnpm dlx asta-ui@latest add textarea-aui-035aui-036Notes card
A notes card that saves as you type.
$ pnpm dlx asta-ui@latest add textarea-aui-036aui-037Product review
A product review with stars.
$ pnpm dlx asta-ui@latest add textarea-aui-037aui-038Code snippet
A code snippet with line numbers.
$ pnpm dlx asta-ui@latest add textarea-aui-038Installation
Run the CLI
Run
pnpm dlx asta-ui@latest initonce, then this. The file lands incomponents/astabyte/and the colour tokens go into your CSS.$ pnpm dlx asta-ui@latest add textareaOr install the package
Don’t want the file? Import from
asta-ui/textareaand update withpnpm update asta-ui. Add the stylesheet once. More.$ pnpm add asta-uiimport { Textarea } from "asta-ui/textarea";Or copy it by hand
Copy this file. Keep the paths, or fix the
@/imports. Then add the tokens fromglobals.css."use client"; import { useLayoutEffect, useRef, useState, type TextareaHTMLAttributes } from "react"; const cx = (...c: (string | false | null | undefined)[]) => c.filter(Boolean).join(" "); export interface TextareaProps extends TextareaHTMLAttributes<HTMLTextAreaElement> { /** Soft character limit: the counter warns near it and turns red past it. */ limit?: number; /** Grow with the content up to this many rows (then scroll). */ maxRows?: number; className?: string; } /** Grows as you type and counts down the characters left with a little ring. */ export function Textarea({ limit, maxRows = 10, rows = 3, className, ...rest }: TextareaProps) { const ref = useRef<HTMLTextAreaElement>(null); const controlled = rest.value !== undefined; const [inner, setInner] = useState(String(rest.defaultValue ?? "")); const value = controlled ? String(rest.value) : inner; useLayoutEffect(() => { const el = ref.current; if (!el) return; const cs = getComputedStyle(el); const line = parseFloat(cs.lineHeight) || 20; const pad = parseFloat(cs.paddingTop) + parseFloat(cs.paddingBottom); el.style.height = "auto"; const h = Math.min(el.scrollHeight, line * maxRows + pad); el.style.height = `${Math.max(h, line * rows + pad)}px`; el.style.overflowY = el.scrollHeight > h + 1 ? "auto" : "hidden"; }, [value, maxRows, rows]); const left = limit ? limit - value.length : 0; const k = limit ? Math.min(1, value.length / limit) : 0; const tone = !limit ? "" : left < 0 ? "var(--color-ink)" : left <= Math.max(10, limit * 0.1) ? "var(--color-ink-2)" : "var(--color-brand)"; const C = 2 * Math.PI * 7; return ( <div className={cx( "relative w-full rounded-xl bg-paper text-ink transition-shadow duration-200", left < 0 ? "shadow-[inset_0_0_0_1.5px_var(--color-ink)]" : "shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--color-ink)_14%,transparent)] hover:shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--color-ink)_24%,transparent)] focus-within:!shadow-[inset_0_0_0_1px_var(--color-brand),0_0_0_4px_color-mix(in_srgb,var(--color-brand)_16%,transparent)]", rest.disabled && "opacity-50", className, )} > <textarea ref={ref} rows={rows} aria-invalid={left < 0 || undefined} {...rest} onChange={(e) => { if (!controlled) setInner(e.target.value); rest.onChange?.(e); }} className={cx( // perf-ok: auto-grow follows the text one line at a time, a short height change on a small field. "block w-full resize-none bg-transparent px-3.5 pt-3 text-[16px] sm:text-[14px] leading-[1.55] outline-none placeholder:text-mute transition-[height] duration-150", limit ? "pb-10" : "pb-3", )} /> {limit !== undefined && ( <div className="pointer-events-none absolute bottom-2.5 right-3 flex items-center gap-2" aria-live="polite"> <span className={cx("text-[12px] tabular-nums transition-[opacity,color] duration-300", left > limit * 0.25 ? "opacity-0" : "opacity-100")} style={{ color: tone }} > {left} </span> <svg viewBox="0 0 18 18" className={cx("h-[18px] w-[18px] -rotate-90 transition-transform duration-300", left < 0 && "scale-110")} aria-hidden> <circle cx="9" cy="9" r="7" fill="none" stroke="color-mix(in srgb, var(--color-ink) 12%, transparent)" strokeWidth="2" /> <circle cx="9" cy="9" r="7" fill="none" stroke={tone} strokeWidth="2" strokeLinecap="round" strokeDasharray={C} strokeDashoffset={C * (1 - k)} className="transition-[stroke-dashoffset,stroke] duration-200" /> </svg> <span className="sr-only">{left >= 0 ? `${left} characters left` : `${-left} characters over the limit`}</span> </div> )} </div> ); } export default Textarea;Or ask your AI agent
Paste this into Claude Code, Cursor, Codex, v0 or Lovable. Fill in the last line. More in Prompts.
Add the Astabyte UI Textarea component to my project. Grows with its text and counts what's left. It includes: autosize, counter, limit. Install it: ```sh pnpm dlx asta-ui@latest add textarea --radix ``` Or with the shadcn CLI: ```sh pnpm dlx shadcn@latest add https://ui.astabyte.com/r/textarea.json ``` If the project isn't set up yet, run `pnpm dlx asta-ui@latest init --radix` first: it runs `shadcn init` when needed and adds the @astabyte registry (Next.js, Vite, React Router, Astro, TanStack Start; Tailwind CSS v4). Import it like this: ```tsx import { Textarea } from "@/components/astabyte/textarea"; ``` Usage example and props: https://ui.astabyte.com/textarea Full catalogue for context: https://ui.astabyte.com/llms.txt Rules: - Keep the colour tokens (paper, paper-2, ink, ink-2, mute, brand). Don't restyle with hard-coded colours; rebrand by changing the token values in the CSS. - Keep the motion as it is: transform and opacity only, and the prefers-reduced-motion fallback. - Keep keyboard, focus and ARIA behaviour. - Use fake data and fake brand names in examples. Use it to: [describe where it goes and what it should do]Or use plain HTML + CSS
Not on React? Use it from Django, Rails, Laravel, Go
html/template, htmx or a static page. Loadasta.cssandasta.jsonce (thehead.htmltab), then paste the markup. Theui.astabyte.com/cdnlink is temporary: pin a version from jsDelivr for production. More in HTML + CSS.<div class="asta-textarea" style="max-width:420px"> <textarea class="asta-textarea-control asta-textarea-auto" name="note" rows="3" aria-label="Note" placeholder="Leave a note for the Astabyte team…"></textarea> </div>
Usage
The demo above, as code.
"use client";
import { Textarea } from "@/components/astabyte/textarea";
export default function TextareaDemo() {
return (
<div className="flex min-h-[420px] w-full items-center justify-center p-6 sm:p-10">
<div className="flex w-full max-w-md flex-col gap-2">
<label htmlFor="brief" className="text-[13px] font-medium text-ink">
Project brief
</label>
<Textarea
id="brief"
name="brief"
limit={160}
maxRows={8}
placeholder="Describe what you're building and who it's for…"
defaultValue="A booking app for small climbing gyms. Members reserve a slot, staff see who's coming. It should feel quick on a phone."
/>
<p className="text-[12.5px] text-mute">It grows as you type. Keep it under 160 characters.</p>
</div>
</div>
);
}