Skip to content
All components
Forms

Textarea

Collect multiline free-form text that grows with its content.

A multi-line field that grows with its content.

Installation

tdpxl is not an npm dependency of your app. The @tdpxl/cli command (not published to npm yet) copies the source into your project, with the registry items and npm packages it imports.

npx @tdpxl/cli add textarea

Then import it from @/components/ui/textarea. New project? Start with the installation guide.

Examples

Each example is one branch of the official demo, rendered in its own frame. The code is that branch as you would write it, with imports pointing at the default install paths.

With label

Collect multiline text with a visible associated label. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import * as React from "react"

import { Label } from "@/components/ui/label"
import { Textarea } from "@/components/ui/textarea"

export function TextareaWithLabel() {
  const id = React.useId()
  

  return (
    <div className="flex w-full max-w-sm flex-col gap-6">
      <div className="flex flex-col gap-1.5">
        <Label htmlFor="textarea-demo">Release notes</Label>
        <Textarea
          id="textarea-demo"
          rows={4}
          placeholder="What changed in this version?"
        />
      </div>
    </div>
  )
}

Character count

Show a character count in the hint while enforcing a maximum length. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import * as React from "react"

import { Field, FieldDescription, FieldLabel } from "@/components/ui/field"

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

const BIO_LIMIT = 160

export function TextareaCharacterCount() {
  const id = React.useId()
  const [bio, setBio] = React.useState("Product designer working on onboarding and forms.")

  return (
    <div className="flex w-full max-w-sm flex-col gap-6">
      <Field>
        <FieldLabel htmlFor={`${id}-bio`}>Bio</FieldLabel>
        <Textarea
          id={`${id}-bio`}
          maxLength={BIO_LIMIT}
          value={bio}
          onChange={(event) => setBio(event.target.value)}
          aria-describedby={`${id}-bio-hint`}
        />
        <FieldDescription id={`${id}-bio-hint`}>
          Shown on your public profile. {bio.length} of {BIO_LIMIT} characters.
        </FieldDescription>
      </Field>
    </div>
  )
}

Invalid

Associate the textarea with its error text. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import * as React from "react"

import { Field, FieldError, FieldLabel } from "@/components/ui/field"

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

export function TextareaInvalid() {
  const id = React.useId()
  

  return (
    <div className="flex w-full max-w-sm flex-col gap-6">
      <Field>
        <FieldLabel htmlFor={`${id}-reason`}>Reason for the refund</FieldLabel>
        <Textarea
          id={`${id}-reason`}
          defaultValue="Broken"
          aria-invalid
          aria-describedby={`${id}-reason-error`}
        />
        <FieldError id={`${id}-reason-error`}>
          Describe the problem in at least 20 characters so we can review it.
        </FieldError>
      </Field>
    </div>
  )
}

Disabled

Inspect the unavailable control using its real disabled semantics. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import * as React from "react"

import { Field, FieldDescription, FieldLabel } from "@/components/ui/field"

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

export function TextareaDisabled() {
  const id = React.useId()
  

  return (
    <div className="flex w-full max-w-sm flex-col gap-6">
      <Field>
        <FieldLabel htmlFor={`${id}-off`}>Internal notes</FieldLabel>
        <Textarea id={`${id}-off`} disabled aria-describedby={`${id}-off-hint`} />
        <FieldDescription id={`${id}-off-hint`}>
          Only editors can add internal notes.
        </FieldDescription>
      </Field>
    </div>
  )
}

Read only

Keep multiline content readable and focusable while preventing edits. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import * as React from "react"

import { Field, FieldDescription, FieldLabel } from "@/components/ui/field"

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

export function TextareaReadOnly() {
  const id = React.useId()
  

  return (
    <div className="flex w-full max-w-sm flex-col gap-6">
      <Field>
        <FieldLabel htmlFor={`${id}-original`}>Original request</FieldLabel>
        <Textarea
          id={`${id}-original`}
          readOnly
          defaultValue="Please move my delivery to the following week. I will be away until the 14th."
          aria-describedby={`${id}-original-hint`}
        />
        <FieldDescription id={`${id}-original-hint`}>
          Read-only. Quote it in your reply if needed.
        </FieldDescription>
      </Field>
    </div>
  )
}

Grows with content

Grow with the content up to a maximum height, then scroll. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import * as React from "react"

import { Field, FieldDescription, FieldLabel } from "@/components/ui/field"

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

export function TextareaGrowsWithContent() {
  const id = React.useId()
  

  return (
    <div className="flex w-full max-w-sm flex-col gap-6">
      <Field>
        <FieldLabel htmlFor={`${id}-notes`}>Meeting notes</FieldLabel>
        <Textarea
          id={`${id}-notes`}
          className="max-h-48"
          aria-describedby={`${id}-notes-hint`}
        />
        <FieldDescription id={`${id}-notes-hint`}>
          The box grows as you type, then scrolls once it reaches its maximum height.
        </FieldDescription>
      </Field>
    </div>
  )
}

API reference

Generated from the component's TypeScript signatures. Inherited DOM and primitive props are listed separately.

Textarea

Collect multiline free-form text.

Textarea props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
Inherited props (24)
Textarea inherited props
PropTypeDefaultDescription
refReact.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).
autoCompletestring | undefined—Native autocomplete hint appropriate to the field's actual purpose.
disabledboolean | undefined—Make the supported control unavailable through its native or primitive disabled semantics. This does not disable arbitrary child links.
formstring | undefined—ID of the form associated with this control, including when it is rendered outside that form element.
maxLengthnumber | undefined—Maximum allowed text length for native input or code entry.
minLengthnumber | undefined—Minimum allowed text length for native validation.
namestring | undefined—Name used by the control's form submission or primitive form integration.
placeholderstring | undefined—Prompt shown before a value is selected or entered. Supply an accessible label separately.
readOnlyboolean | undefined—Prevent value editing while preserving readable content. Read-only behavior differs from disabled behavior.
requiredboolean | undefined—Mark this control as required using its native or primitive semantics. Consumers own contextual validation feedback.
rowsnumber | undefined—Visible row count for a native textarea. Preserve resizing and content access in the surrounding layout.
valuestring | number | readonly string[] | undefined—Current value in the shape defined by the source type. For controlled interactive inputs, apply updates from the change callback.
onChangeReact.ChangeEventHandler<HTMLTextAreaElement, HTMLTextAreaElement> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLTextAreaElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLTextAreaElement> | undefined—Receive the native blur event when focus leaves this control.
onKeyDownReact.KeyboardEventHandler<HTMLTextAreaElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLTextAreaElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLTextAreaElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.

Accessibility & usage

From registry/ui/textarea.meta.json (authored guidance; human review may still be pending). Behavior is checked by Storybook tests, not certified here.

When to use

  • Comments, descriptions, notes, messages and any answer that may run over one line.
  • Text with a length limit, paired with a visible character count in the hint.
  • Read-only text people need to read or quote, with readOnly so it stays focusable and selectable.

When not to use

  • A short single-line value such as a name or an email address.
  • Rich text with formatting; a textarea only holds plain text.
  • Structured data that a set of specific fields would validate better.

Anatomy

Textarea
The native textarea element with field-sizing: content and a minimum height of 80 CSS px; native attributes (rows, maxLength, required, readOnly) pass through.
Label
A Label or FieldLabel whose htmlFor matches the textarea id.
Hint or error
FieldDescription or FieldError referenced from aria-describedby; aria-invalid switches the border to the error role.

Keyboard & interaction

  • Enter inserts a line break; it never submits the form. Provide a visible submit button.
  • Native editing, selection, spell checking and undo come from the browser.
  • Focus uses the border and focus shadow on keyboard focus; aria-invalid swaps both to the error role.
  • Disabled textareas leave the Tab order; readOnly ones stay focusable and selectable.

Responsive behavior

  • Full width by default; it never forces horizontal scrolling at 320 CSS px.
  • In browsers that support CSS field-sizing it grows with the content from its minimum height; elsewhere it keeps the rows height and scrolls. Add a max-height class so long text scrolls inside the box.
  • Inside dialogs, sheets and drawers, cap the height so the action buttons stay visible when the on-screen keyboard is open.
  • Keep the label above the box on every screen size.

Content guidelines

  • Label: name the content ('Release notes', 'Reason for the refund').
  • Hint: say who sees the text and any limit ('Shown on your public profile. 42 of 160 characters.').
  • Error: explain the minimum or the problem ('Describe the problem in at least 20 characters').
  • Placeholder: an optional example of a good answer, never the instructions themselves.

Alternatives

  • Input — A single-line value.
  • Field — The wrapper that associates label, hint or error with the textarea.
  • Form — React Hook Form validation for the textarea and the rest of the form.

Resources