Textarea
FreeNewA multi-line field that grows with its content up to a row limit, with an optional character counter.
Installation
pnpm dlx shadcn@latest add @viewport/textarea
First time? Add the @viewport registry to components.json. Setup takes one minute.
Usage
The code behind the preview above.
import { Textarea } from "@/components/viewport/textarea";
export default function TextareaDemo() {
return (
<div className="flex w-full max-w-sm flex-col gap-3">
<Textarea aria-label="Note" autosize rows={2} maxRows={8} placeholder="Add a note. The field grows as you type." />
<Textarea aria-label="Bio" showCount maxLength={160} rows={3} defaultValue="Head of Revenue at Northwind. Previously led partnerships across the Nordics, and still answers every renewal email personally." />
</div>
);
}Props
| Prop | Type | Default |
|---|---|---|
| autosize | booleanGrow with the text instead of scrolling, up to `maxRows`. | false |
| maxRows | numberThe tallest the field gets when `autosize` is set. After that it scrolls. | 10 |
| showCount | booleanShow how many characters are used. Needs `maxLength`. | false |
Accessibility
- The counter is visual; a polite message reads the characters left only near the limit.
- Grows with CSS where the browser supports it, so there is no measuring on each key.
- Respects prefers-reduced-motion.