Textarea
A textarea takes text that runs over several lines, such as notes or a description, and grows with its content.
When to use
Section titled “When to use”- Use it for notes, descriptions and messages.
- Use an Input for one line, such as a name or a title.
- Put it in a Field, with a hint that says the limit, such as “Paling banyak 500 karakter.”
Paling banyak 500 karakter.
Paling banyak 500 karakter.
Anatomy
Section titled “Anatomy”- 1Label
- 2Field that grows with its text
- 3Resize handle
A box on radius-md with an input border, at least min-h-16 tall, that grows with its content (field-sizing-content). Focus shows the ring; an invalid value turns the border destructive.
Variants
Section titled “Variants”There is one style.
| React | Vue | Flutter | Type | Default | Use |
|---|---|---|---|---|---|
value / defaultValue |
v-model / default-value |
controller / initialValue |
text | none | The text. |
maxLength |
maxlength |
maxLength |
number | none | The longest text allowed. Say it in the hint too. |
rows |
rows |
minHeight |
number | grows with content | The starting height. |
aria-invalid |
aria-invalid |
forceErrorText on ShadTextareaFormField |
boolean | false |
Marks a refused value. |
disabled |
disabled |
enabled: false |
boolean | false |
Blocks typing. |
import { useId } from "react"import { Field, FieldDescription, FieldLabel } from "@/components/ui/field"import { Textarea } from "@/components/ui/textarea"
export default function TextareaDemo() { const id = useId() return ( <Field className="w-full max-w-sm"> <FieldLabel htmlFor={`${id}-notes`}>Catatan untuk tim</FieldLabel> <Textarea id={`${id}-notes`} maxLength={500} aria-describedby={`${id}-notes-hint`} /> <FieldDescription id={`${id}-notes-hint`}>Paling banyak 500 karakter.</FieldDescription> </Field> )}<script setup lang="ts">import { useId } from "vue"import { Field, FieldDescription, FieldLabel } from "@/components/ui/field"import { Textarea } from "@/components/ui/textarea"
const id = useId()</script>
<template> <Field class="w-full max-w-sm"> <FieldLabel :for="`${id}-notes`">Catatan untuk tim</FieldLabel> <Textarea :id="`${id}-notes`" :maxlength="500" :aria-describedby="`${id}-notes-hint`" /> <FieldDescription :id="`${id}-notes-hint`">Paling banyak 500 karakter.</FieldDescription> </Field></template>import 'package:flutter/widgets.dart';import 'package:shadcn_ui/shadcn_ui.dart';
class TextareaDemo extends StatelessWidget { const TextareaDemo({super.key});
@override Widget build(BuildContext context) { final theme = ShadTheme.of(context); // ShadTextareaFormField does not pass maxLength on, so the label and hint sit around a ShadTextarea. return ConstrainedBox( constraints: const BoxConstraints(maxWidth: 384), child: Column( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, spacing: 8, children: [ Text('Catatan untuk tim', style: theme.textTheme.small), const ShadTextarea(maxLength: 500), Text('Paling banyak 500 karakter.', style: theme.textTheme.muted), ], ), ); }}Install
Section titled “Install”npx shadcn@latest add https://design.sosialoka.tech/r/react/textarea.jsonnpx shadcn-vue@latest add https://design.sosialoka.tech/r/vue/textarea.jsonAccessibility
Section titled “Accessibility”- Give it a visible label in a Field.
- Tie the hint and any error to it with
aria-describedby. - It keeps the native
textareakeyboard behavior: Enter adds a line, Tab moves on.
