Skip to content
WunderUI

Textarea

Free

Take text over several lines, such as a message, a description or feedback.

npx wunderui-cli add textarea

Playground

Include steps to reproduce if you can.

Installation

bash
npx wunderui-cli add textarea

Writes the source into your project with its dependencies and, on first use, the styles - see Installation.

Then import what you need:

tsx
import { Textarea } from "@/components/ui/textarea"
import type { TextareaProps } from "@/components/ui/textarea"

Then use it:

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

export function Feedback() {
  return <Textarea id="feedback" label="Your feedback" placeholder="Tell us what happened" maxLength={200} showCount />
}

Expected result: The label Your feedback above a white box with a grey placeholder and the counter 0/200 in the corner. Clicking the label focuses the field.

When to use

Use Textarea for

  • Text over several lines, such as a message, a comment or feedback
  • A description or a note that can be a paragraph or two
  • A field with a limit that people should see while typing

Use something else for

  • Input for one line of text, such as a name or an email address
  • Prompt Input for a chat input that grows and has attach and send buttons

Sizes

Three minimum heights, 72, 96 and 128 px, and 80, 112 and 144 px in comfortable density. People can still drag the field taller.

Label, helper, error and counter

Pass a label and the field is joined to it. A helper states the rule, an error replaces it with what to do, optional marks the exception, and the counter appears only with a limit.

Resize

A field is vertical by default: the handle in the corner drags it taller. Fix the height where the layout must not move, or let the field grow with what is typed.

States

Hover and focus are real states: point at the field, or press Tab. A wrong value turns the border and the ring red, and the fill stays white.

Include steps to reproduce if you can.

Keyboard interactions

A textarea is one tab stop and takes the keys of a native text field. Typing, selecting and system shortcuts are the browser's.

TaborShiftTab
Moves focus into and out of the field. A disabled field is skipped; a read-only field keeps its place in the order.
Enter
Starts a new line. It does not send the form; give the form a button, or handle yourself.

Behavior and motion

What the textarea does itself, and what it leaves to the page.

A native element
Textarea renders a native textarea inside a wrapper, so every attribute works: name, value, maxLength, required, readOnly, rows and the rest. The wrapper only holds the counter.
One component, two shapes
With no field props it renders the bare field. With a label, helper, error or optional tag it adds label, control and message in one column, and an error appearing keeps the same textarea and focus.
Controlled or not
Pass a value and change handler to own the text, or a default value to let the field keep it. The counter follows either way.
Size and density
Size sets the minimum height: 72, 96 or 128 px by default, 80, 112 or 144 px at comfortable density. The field grows taller when the text does.
Counter
Show count with a maximum length shows length and maximum in the bottom-right corner and adds room below the text. Without a maximum there is nothing to count, so no counter appears.
Resize
By default people can drag the field taller. You can fix the height instead, or let the field grow with its text and add a maximum height so it scrolls at some point.
Invalid
An error marks the field invalid, turns the border and focus ring red and replaces the helper with a red message, while the fill stays white. Without field props, it only reddens the border.
Disabled and read-only
Disabled dims the field to 40 % with its label and helper, skips it in the tab order and leaves it out of the form data. Read-only stays readable, focusable, copyable and submitted, on a subtle fill.
Motion
The border colour fades when the pointer enters or the field takes focus. Nothing moves or scales.
Reduced motion
With reduced motion the same colour change stays, since it is a short fade and not movement.

Anatomy

Textarea is the field itself. With the field props it also draws the label above and the helper or error line below, and the field draws the counter.

41/200
  • The visible name of the field. Clicking it focuses the textarea, and a field without a visible label needs an aria-label.

  • data-slot="textarea-field"

    The multi-line field: a native textarea with a 1 px border and an 8 px corner. Its minimum height follows size and density (72, 96 or 128 px), and longer text scrolls inside.

  • Optional

    Shows length and maximum in the bottom-right corner when both show count and a maximum are set. The field reserves room below the text, so the counter never covers a line.

  • Optional

    The browser's handle in the bottom-right corner that drags the field taller. It is on by default and can be removed.

  • Optional

    A 12 px line under the field: a helper with the rule, or an error with what to do. The error replaces the helper, both are linked to the textarea, and an error also marks the field invalid.

  • data-slot="textarea"
  • Optional

Best practices

  • Do

    Give it a visible label. A placeholder disappears with the first keystroke and isn't a name.

  • Do

    Set a maximum length together with show count when there is a limit. The counter needs both, and the field stops accepting text at the limit.

  • Do

    Say what to do in the error, such as Enter at least 20 characters, and keep what the person typed. Show it after they leave the field or send the form.

  • Do

    Pick the size for the text you expect: small for a note, default for a message, large for a description. People can still drag the field taller.

  • Do

    Mark the exception, not the rule. When most fields are needed, flag the few optional ones instead of putting a star on every other label.

  • Don’t

    Don't import TextareaField in new code. It is a deprecated alias, so use Textarea with the same props.

  • Don’t

    Don't size it with rows or height classes. Pick a size instead, because the heights follow density and stay right in compact and comfortable.

  • Don’t

    Don't hide the counter and cut the text off silently. A limit people can't see feels like a bug.

  • Don’t

    Don't put a chat composer's buttons next to the field by hand. Put the field and its buttons in one box that owns the border and focus ring.

API reference

Textarea renders a native textarea inside a wrapper and takes all its attributes. The table lists the props the library adds: size, show count and the field props.

The multi-line field: a native textarea with a 1 px border and an 8 px corner. Its minimum height follows size and density (72, 96 or 128 px), and longer text scrolls inside.

PropTypeDefaultDescription
size"default" | "lg" | "sm"—The minimum height of the field. is 72 px, 96 px and 128 px at the default density, and 80, 112 and 144 px in . People can still drag the field taller.
labelReactNode—The visible name of the field. Joined to the textarea with . Any field prop makes Textarea render the label, the field and the message line instead of the bare field.
helperReactNode—A hint under the field in 12 px tertiary text, linked with . Replaced by while there is one.
errorReactNode—The message under the field in the error colour. Sets , turns the border and the ring red and replaces .
optionalboolean—Adds the tag after the label. It is part of the accessible name.
wrapperClassNamestring—Class names for the column around label, field and message. still goes to the .
showCountboolean—Shows a counter in the bottom-right corner and adds room below the text for it. It needs ; without it nothing is drawn.

PropTypeDefaultDescription
errorReactNode—Error message below the field. Sets and .
helperReactNode—Hint below the field. Replaced by while there is one.
labelReactNode—Visible label. Joined to the control with .
optionalboolean—Adds the "(optional)" tag to the label.
showCountboolean—Show a "n/maxLength" character counter in the bottom-right corner. Requires maxLength.
size"default" | "lg" | "sm"—
wrapperClassNamestring—Class names for the wrapper around label, field and message.

Notes for AI

Give your coding assistant the Markdown reference instead of screenshots.

MCPget_component("textarea")
Installnpx wunderui-cli add textarea

The full library index for assistants is at /llms.txt.