Theme

Customize appearance

Components

Textarea

Collect longer text that may span several lines.

View component source ↗

Preview

A minimal example to get started.

Installation

Install this component and its dependencies in a project initialized with shadcn.

pnpm dlx shadcn@latest add https://ui.hyunjoon.net/r/textarea.json

Usage

This is the basic example. Use the Code tab above for the selected example. Adjust import aliases to match your project.

import { Textarea } from "@/components/ui/textarea";

export default function Example() {
  return (
    <Textarea
      aria-label="Project description"
      placeholder="Describe your project…"
      className="max-w-sm"
    />
  );
}

API reference

Derived from the installed component types. Native DOM props are also supported where applicable. A dash means no explicit default is documented. Some props depend on the selected mode.

Textarea
Textarea properties
PropTypeDefaultDescription
ref
React.Ref<HTMLTextAreaElement> | undefined
React.Ref<HTMLTextAreaElement> | undefined
—Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref).
disabled
boolean | undefined
boolean | undefined
—Prevents user interaction.
maxLength
number | undefined
number | undefined
—Maximum number of input characters.
name
string | undefined
string | undefined
—Field name used in form data.
placeholder
string | undefined
string | undefined
—Hint shown when the control has no value.
required
boolean | undefined
boolean | undefined
—Whether the user must provide a value before form submission.
rows
number | undefined
number | undefined
—Initial number of visible text rows.
value
string | number | readonly string[] | undefined
string | number | readonly string[] | undefined
—The current value when controlled by the application.
onChange
React.ChangeEventHandler<HTMLTextAreaElement, HTMLTextAreaElement> | undefined
React.ChangeEventHandler<HTMLTextAreaElement, HTMLTextAreaElement> | undefined
—Called when the underlying form control changes; inspect the event for its value.
defaultChecked
boolean | undefined
boolean | undefined
—Initial checked state for an uncontrolled control.
defaultValue
string | number | readonly string[] | undefined
string | number | readonly string[] | undefined
—Initial value for an uncontrolled component.
className
string | undefined
string | undefined
—Additional CSS classes merged with the component styles.
id
string | undefined
string | undefined
—Unique identifier used to associate labels and descriptions.
children
React.ReactNode
React.ReactNode
—Content rendered inside this component.
onFocus
React.FocusEventHandler<HTMLTextAreaElement> | undefined
React.FocusEventHandler<HTMLTextAreaElement> | undefined
—Called when the control receives focus.
onBlur
React.FocusEventHandler<HTMLTextAreaElement> | undefined
React.FocusEventHandler<HTMLTextAreaElement> | undefined
—Called when the control loses focus.
onKeyDown
React.KeyboardEventHandler<HTMLTextAreaElement> | undefined
React.KeyboardEventHandler<HTMLTextAreaElement> | undefined
—Called when a key is pressed while this element is focused.
onClick
React.MouseEventHandler<HTMLTextAreaElement> | undefined
React.MouseEventHandler<HTMLTextAreaElement> | undefined
—Called when the element is activated.

Usage notes

Supply a visible label and choose a useful starting size. Keep validation and character limits close to the field.