When to use
- Free text that runs to a few lines: a reply to a support ticket, a review, a note on an order.
- Text with a length limit people should see as they type, such as a 280-character post: set
maxLengthand the counter turns on. - A box that should start small and grow as people write, up to a cap, rather than a fixed tall box.
When not to use
Installation
pnpm dlx shadcn add https://eased.dev/r/textarea.jsonnpx shadcn add https://eased.dev/r/textarea.jsonyarn dlx shadcn add https://eased.dev/r/textarea.jsonbunx --bun shadcn add https://eased.dev/r/textarea.jsonThe command adds Textarea, everything it builds on and Eased’s tokens to your project.
Install the dependencies
pnpm add @base-ui/react motionnpm install @base-ui/react motionyarn add @base-ui/react motionbun add @base-ui/react motionAdd the Eased pieces it builds on
Copy each item’s files the same way, or install them with the CLI:
Copy the source into your project
components/eased/textarea/textarea.tsxTSX "use client";import { Field as BaseField } from "@base-ui/react/field";import { animate, motion, useMotionValue, type AnimationPlaybackControls } from "motion/react";import { useCallback, useLayoutEffect, useRef, useState, type ComponentProps } from "react";import { InputGroup, controlClass, controlPadClass, type ControlSize } from "../_primitives/field/field";import { NumberRoll } from "../_primitives/number-roll/number-roll";import { smooth, useSafeReducedMotion } from "../lib/motion";export type TextareaProps = Omit<ComponentProps<"textarea">, "className" | "rows"> & { /** Height when empty, in lines. Default 3. */ minRows?: number; /** Grow up to this many lines, then scroll. Default 8. */ maxRows?: number; /** Called with the new text on every change. */ onValueChange?: (value: string) => void; /** * Show a `count / maxLength` counter under the text. Default: on when `maxLength` is set. * Its digits roll, and it turns warning-coloured at 90% of the limit. */ showCount?: boolean; /** Mark the textarea invalid outside a `Field` (inside one, the field's validity drives it). */ invalid?: boolean; /** Type size, radius and padding, matching Input: sm (13px text), md (default), lg. */ size?: ControlSize; /** Classes for the bordered shell. */ className?: string; /** Classes for the `<textarea>` itself. */ controlClassName?: string;};const PAD_Y: Record<ControlSize, string> = { sm: "py-1.5", md: "py-2", lg: "py-2.5" };/** * A textarea that grows with its text on a smooth spring instead of jumping a line at a time. * The `<textarea>` itself is sized at once (so the caret never scrolls out of view) and a clip * around it springs to the new height. Built on Base UI's Field.Control, so it labels, * describes and validates itself inside a `Field`. */export function Textarea({ minRows = 3, maxRows = 8, onValueChange, showCount, invalid, size = "md", className = "", controlClassName = "", maxLength, value, defaultValue, ...props}: TextareaProps) { const reduced = useSafeReducedMotion(); const ref = useRef<HTMLTextAreaElement>(null); const height = useMotionValue<number | "auto">("auto"); const spring = useRef<AnimationPlaybackControls | null>(null); const [typed, setTyped] = useState(() => String(defaultValue ?? "").length); const count = value !== undefined ? String(value).length : typed; const counted = showCount ?? maxLength !== undefined; const resize = useCallback( (animated: boolean) => { const el = ref.current; if (!el) return; const cs = getComputedStyle(el); const line = parseFloat(cs.lineHeight) || 20; const chrome = parseFloat(cs.paddingTop) + parseFloat(cs.paddingBottom); const min = minRows * line + chrome; const max = maxRows * line + chrome; el.style.height = "0px"; const content = el.scrollHeight; const target = Math.round(Math.min(max, Math.max(min, content))); el.style.height = `${target}px`; el.style.overflowY = content > max + 1 ? "auto" : "hidden"; const from = height.get(); if (from === target) return; spring.current?.stop(); if (!animated || reduced || from === "auto") height.jump(target); else spring.current = animate(height, target, smooth); }, [minRows, maxRows, reduced, height], ); // Size before first paint; re-measure without animating when the width changes (rewrap). useLayoutEffect(() => { const el = ref.current; if (!el) return; resize(false); let width = el.offsetWidth; const ro = new ResizeObserver(() => { if (el.offsetWidth === width) return; width = el.offsetWidth; resize(false); }); ro.observe(el); return () => ro.disconnect(); }, [resize]); // A controlled value can change without typing (a reset, a suggestion). useLayoutEffect(() => { if (value !== undefined) resize(true); }, [value, resize]); return ( <InputGroup multiline size={size} invalid={invalid} className={className}> <motion.div style={{ height }} className="relative [overflow:clip]"> <BaseField.Control {...(props as ComponentProps<typeof BaseField.Control>)} {...(invalid !== undefined ? { "aria-invalid": invalid } : null)} ref={ref} value={value as string | undefined} defaultValue={defaultValue as string | undefined} onValueChange={(v) => { if (value === undefined) setTyped(v.length); onValueChange?.(v); resize(true); }} render={(p) => <textarea {...(p as ComponentProps<"textarea">)} rows={minRows} maxLength={maxLength} />} className={`${controlClass} block w-full resize-none ${controlPadClass[size]} ${PAD_Y[size]} [scrollbar-width:thin] ${controlClassName}`} /> </motion.div> {counted && maxLength !== undefined && <Counter count={count} max={maxLength} pad={controlPadClass[size]} />} </InputGroup> );}/** `count / max`, digits rolling in the direction of change; warning colour from 90%. */function Counter({ count, max, pad }: { count: number; max: number; pad: string }) { const near = count >= max * 0.9; return ( <div className={`flex justify-end pb-2 select-none ${pad}`}> <span aria-hidden className={`inline-flex items-center text-ui-xs tabular-nums transition-colors duration-150 ease-standard ${ near ? "text-warning-text" : "text-text-muted" }`} > <NumberRoll value={count} format={{ useGrouping: false }} aria-hidden /> <span className="text-text-muted">/{max}</span> </span> {/* Announce the thresholds, not every keystroke. */} <span role="status" className="sr-only"> {count >= max ? "Character limit reached" : near ? `Approaching the ${max} character limit` : ""} </span> </div> );}Keep the folder layout
The files import each other by relative path (
../lib/motion), so keep each one at the path shown, undercomponents/eased/.
Usage
import { useState } from "react";import { Field } from "@/components/eased/field/field";import { Textarea } from "@/components/eased/textarea/textarea";export function Reply() { const [text, setText] = useState(""); return ( <Field label="Reply"> <Textarea value={text} onValueChange={setText} maxLength={280} minRows={2} maxRows={6} placeholder="Write a reply…" /> </Field> );}Examples
Without a counter
showCount={false} keeps the native limit but hides the counter, for limits people are unlikely to reach.
<Field label="Delivery note" description="Gate codes, where to leave it."> <Textarea name="note" maxLength={500} showCount={false} minRows={2} /></Field>Standalone
Outside a Field, name it with aria-label and drive the error state with invalid.
<Textarea aria-label="Feedback" size="sm" minRows={4} invalid={tooShort} />API reference
Textarea
| Prop | Type | Default | Description |
|---|---|---|---|
minRows | number | 3 | Height when empty, in lines. |
maxRows | number | 8 | Grows up to this many lines, then scrolls. |
value | string | Controlled text. | |
defaultValue | string | Uncontrolled starting text. | |
onValueChange | (value: string) => void | Called with the new text on every change. | |
maxLength | number | The native limit. Turns the counter on. | |
showCount | boolean | maxLength !== undefined | Shows a count/max counter under the text. It needs maxLength. |
invalid | boolean | Marks the textarea invalid outside a Field. Inside one, the field's validity drives it. | |
size | "sm" | "md" | "lg" | "md" | Type size, radius and padding, matching Input. |
className | string | "" | Classes for the bordered shell. |
controlClassName | string | "" | Classes for the <textarea> itself. |
Every other <textarea> prop passes through (name, placeholder, disabled, onKeyDown …) except rows, which minRows sets.
Accessibility
- Inside a Field, Base UI ties the label to the textarea and points
aria-describedbyat the description and error. Outside one, passaria-label. - The counter is hidden from screen readers. A status line announces only "Approaching the 280 character limit" at 90% and "Character limit reached" at the limit, not every keystroke.
- The counter turns warning-coloured at 90%, and the native limit stops typing at
maxLength. - Text is 16px on touch screens so iOS does not zoom in on focus.
Motion
As you type, the textarea itself is sized at once, so the caret never scrolls out of view, and a clip around it springs to the new height on the smooth spring instead of jumping a line at a time. A controlled value that changes without typing (a reset, an inserted template) springs the same way; a change of width re-measures without animating. The counter's digits roll in the direction of change on the snappy spring, and its colour changes over 150ms. Focus and error states are the same as Input: a border step, a soft glow, and one 6px shake when it turns invalid. Reduced motion jumps the height, changes the digits in place and drops the shake.
Notes for AI
Use Textarea for plain multi-line text inside a Field. Set minRows and maxRows to fit the space, and maxLength when there is a real limit; the counter and its announcements come with it.
Do not add your own autosize logic, counter or aria-live region, and do not set rows or a fixed height: the component measures and springs its own height.
Related components
- Animated Text Input: a single line of text.
- Form Field with Validation: the label and message line around it.
- AI Chat Input: a chat input with send and attachments.