Textarea
A multi-line text input.
It grows with what is typed, from 64px, and has no resize handle.
With a label
import { Label } from "@/components/ui/label"
import { Textarea } from "@/components/ui/textarea"
export default function TextareaWithALabel() {
return (
<div className="grid w-full max-w-sm gap-2">
<Label htmlFor="textarea-notes">Release notes</Label>
<Textarea id="textarea-notes" placeholder="What changed in this release" />
</div>
)
}
Grows with its content
import { Label } from "@/components/ui/label"
import { Textarea } from "@/components/ui/textarea"
const summary = `Exports now include archived tasks.
Invoice numbers keep their prefix when duplicated.
The weekly digest is sent on Monday at 09:00.
Fixed a rounding error in the tax column.`
export default function TextareaGrowsWithItsContent() {
return (
<div className="grid w-full max-w-sm gap-2">
<Label htmlFor="textarea-summary">Summary</Label>
<Textarea id="textarea-summary" defaultValue={summary} />
</div>
)
}
Disabled
import { Label } from "@/components/ui/label"
import { Textarea } from "@/components/ui/textarea"
export default function TextareaDisabled() {
return (
<div className="group grid w-full max-w-sm gap-2" data-disabled="true">
<Label htmlFor="textarea-terms">Payment terms</Label>
<Textarea id="textarea-terms" defaultValue="Payment is due 30 days after the invoice date." disabled />
</div>
)
}
Invalid
Give at least 20 characters so finance can approve it.
import { Field, FieldError, FieldLabel } from "@/components/ui/field"
import { Textarea } from "@/components/ui/textarea"
export default function TextareaInvalid() {
return (
<Field data-invalid="true" className="max-w-sm">
<FieldLabel htmlFor="textarea-reason">Reason for the refund</FieldLabel>
<Textarea id="textarea-reason" defaultValue="Duplicate" aria-invalid aria-describedby="textarea-reason-error" />
<FieldError id="textarea-reason-error">Give at least 20 characters so finance can approve it.</FieldError>
</Field>
)
}
Installation
npx shadcn@latest add @khaeli/textareabunx --bun shadcn@latest add @khaeli/textareaInstall @khaeli/foundation first: this item's styling lives in its tokens and [data-slot] rules.
Installs with
- Registry items
Keyboard
Enter- Adds a line.
Tab- Moves focus on. It never types a tab. A
disabledtextarea leaves the tab order.
Accessible name
- Give the textarea an
idand point a @khaeli/label at it withhtmlFor. A placeholder is not a name. - An invalid control carries
aria-invalidand lists theidof its message inaria-describedby, so the message is read as its description. @khaeli/field lays the label, control and message out.
Registry JSON
The item as the shadcn CLI reads it, with every file it ships: https://ui.khaeli.com/r/textarea.json