Skip to content

    Textarea

    Text field over several lines, for a description, a comment or a message. Input's field box: the same raised fill, light edge, 14px text (16px on touch) and states, with container corners that stay finite in the pill preset. One line plus its padding matches the Input height of the same size.

    React

    Preview

    Shown on the project card.

    Props

    • size
    • resize
    • rows
    • disabled
    • maxLength
    • showCount
    • invalid
    • label
    • placeholder
    • error
    import { Field, FieldControl, FieldDescription, FieldLabel } from "@/components/ui/field"
    import { Textarea } from "@/components/ui/textarea"
    
    <Field className="w-96 max-w-full">
      <FieldLabel>Description</FieldLabel>
      <FieldControl>
        <Textarea placeholder="What is this project about?" />
      </FieldControl>
      <FieldDescription>Shown on the project card.</FieldDescription>
    </Field>

    Usage

    When to use

    • Text over several lines: a description, a comment, a message to the team.
    • A value the user pastes in, such as a list of addresses, one per line.

    When not to use

    • A single line, such as a name, an email or a search. Use Input.
    • Picking from known options. Use Select.

    Platform support

    What each platform has, from the spec. A selected platform is highlighted.

    NameWebiOSAndroidNote
    sizeYesYesYes
    resizeYesDeferredDeferredNot generated for iOS and Android.
    rowsYesYesYes
    disabledYesYesYes
    readOnlyYesYesYes
    maxLengthYesDeferredDeferredNot generated for iOS and Android.
    showCountYesDeferredDeferredNot generated for iOS and Android.
    countLabelYesDeferredDeferredNot generated for iOS and Android.
    invalidYesYesYes
    valueNoYesYesOnly on iOS, Android.
    onValueChangeNoYesYesOnly on iOS, Android.
    placeholderNoYesYesOnly on iOS, Android.

    Variants

    size

    Padding and minimum height, matching the Input of the same size. Use the size of the other fields in the form.

    • Shown on the project card.

      sm

    • Shown on the project card.

      mddefault

    • Shown on the project card.

      lg

    • Shown on the project card.

      xl

    import { Field, FieldControl, FieldDescription, FieldLabel } from "@/components/ui/field"
    import { Textarea } from "@/components/ui/textarea"
    
    <Field className="w-96 max-w-full">
      <FieldLabel>Description</FieldLabel>
      <FieldControl>
        <Textarea size="sm" placeholder="What is this project about?" />
      </FieldControl>
      <FieldDescription>Shown on the project card.</FieldDescription>
    </Field>
    <Field className="w-96 max-w-full">
      <FieldLabel>Description</FieldLabel>
      <FieldControl>
        <Textarea placeholder="What is this project about?" />
      </FieldControl>
      <FieldDescription>Shown on the project card.</FieldDescription>
    </Field>
    <Field className="w-96 max-w-full">
      <FieldLabel>Description</FieldLabel>
      <FieldControl>
        <Textarea size="lg" placeholder="What is this project about?" />
      </FieldControl>
      <FieldDescription>Shown on the project card.</FieldDescription>
    </Field>
    <Field className="w-96 max-w-full">
      <FieldLabel>Description</FieldLabel>
      <FieldControl>
        <Textarea size="xl" placeholder="What is this project about?" />
      </FieldControl>
      <FieldDescription>Shown on the project card.</FieldDescription>
    </Field>

    resize

    Which way the user can drag the corner. vertical keeps the width of the form; none for a fixed box, such as a chat composer.

    • Shown on the project card.

      none

    • Shown on the project card.

      verticaldefault

    • Shown on the project card.

      both

    import { Field, FieldControl, FieldDescription, FieldLabel } from "@/components/ui/field"
    import { Textarea } from "@/components/ui/textarea"
    
    <Field className="w-96 max-w-full">
      <FieldLabel>Description</FieldLabel>
      <FieldControl>
        <Textarea resize="none" placeholder="What is this project about?" />
      </FieldControl>
      <FieldDescription>Shown on the project card.</FieldDescription>
    </Field>
    <Field className="w-96 max-w-full">
      <FieldLabel>Description</FieldLabel>
      <FieldControl>
        <Textarea placeholder="What is this project about?" />
      </FieldControl>
      <FieldDescription>Shown on the project card.</FieldDescription>
    </Field>
    <Field className="w-96 max-w-full">
      <FieldLabel>Description</FieldLabel>
      <FieldControl>
        <Textarea resize="both" placeholder="What is this project about?" />
      </FieldControl>
      <FieldDescription>Shown on the project card.</FieldDescription>
    </Field>

    Examples

    Default

    Shown on the project card.

    import { Field, FieldControl, FieldDescription, FieldLabel } from "@/components/ui/field"
    import { Textarea } from "@/components/ui/textarea"
    
    <Field className="w-full max-w-sm">
      <FieldLabel>Description</FieldLabel>
      <FieldControl>
        <Textarea placeholder="What is this project about?" />
      </FieldControl>
      <FieldDescription>Shown on the project card.</FieldDescription>
    </Field>

    With an error

    The error text marks the textarea invalid and is read after its name.

    Tell us in a sentence or two.

    import { Field, FieldControl, FieldError, FieldLabel } from "@/components/ui/field"
    import { Textarea } from "@/components/ui/textarea"
    
    <Field className="w-full max-w-sm" required>
      <FieldLabel>Reason for leaving</FieldLabel>
      <FieldControl>
        <Textarea rows={4} />
      </FieldControl>
      <FieldError>Tell us in a sentence or two.</FieldError>
    </Field>

    Read only

    Focusable and copyable, but not editable.

    import { Field, FieldControl, FieldLabel } from "@/components/ui/field"
    import { Textarea } from "@/components/ui/textarea"
    
    <Field className="w-full max-w-sm">
      <FieldLabel>Webhook payload</FieldLabel>
      <FieldControl>
        <Textarea readOnly rows={4} defaultValue="event: project.created" />
      </FieldControl>
    </Field>

    Disabled

    import { Field, FieldControl, FieldLabel } from "@/components/ui/field"
    import { Textarea } from "@/components/ui/textarea"
    
    <Field className="w-full max-w-sm" disabled>
      <FieldLabel>Notes</FieldLabel>
      <FieldControl>
        <Textarea defaultValue="Archived projects can't be edited." />
      </FieldControl>
    </Field>

    With a character count

    maxLength sets the limit; showCount shows it inside the field.

    35 / 160
    import { Textarea } from "@/components/ui/textarea"
    
    <div className="flex w-full max-w-sm flex-col gap-xs">
      <label htmlFor="bio" className="text-sm text-text-secondary">Bio</label>
      <Textarea id="bio" maxLength={160} showCount defaultValue="Product designer building Werewolf." />
    </div>

    Do and don't

    Do

    • Put it in a Field, so it has a visible label and its description and error are linked.
    • Set rows for the text you expect, so the box shows how much to write.
    • Use the same size as the other fields in the form.

    Don't

    • Don't use it for a single line, such as a name or an email; use Input.
    • Don't use a placeholder instead of a label.
    • Don't make Enter submit the form; people expect a new line.

    Props

    NameTypeValuesDefaultDescription
    sizeenumsm | md | lg | xlmdPadding and minimum height, matching the Input of the same size. Use the size of the other fields in the form.
    resizeenumnone | vertical | bothverticalWhich way the user can drag the corner. vertical keeps the width of the form; none for a fixed box, such as a chat composer. Not generated for iOS and Android.
    rowsnumber-3Visible lines before the text scrolls. Pick it for the text you expect: 3 for a comment, 6 or more for a description.
    disabledboolean-falseCan't be focused or edited. Prefer readOnly for a value the user should still read and copy.
    readOnlyboolean-falseCan be focused, scrolled and copied, but not edited. Same look as an editable textarea.
    maxLengthnumber--Native limit on the number of characters. With showCount, the count reads 34 / 160. Not generated for iOS and Android.
    showCountboolean-falseShows the number of characters typed at the bottom end of the field, out of maxLength when it is set. The textarea is described by the count; a screen reader hears the characters left only near the limit, once typing pauses. Not generated for iOS and Android.
    countLabelfunction--What a screen reader hears near the limit, given the characters left. Defaults to "12 characters left"; pass a translated function on a page in another language. Not generated for iOS and Android.
    invalidboolean-falseSets aria-invalid, which draws the danger border. Pair it with error text in color-text-danger linked through aria-describedby.
    valuestring--Native only: the text in the field. Pair it with onValueChange; the field keeps no state of its own. Only on iOS, Android.
    onValueChangefunction--Native only: called with the new text after every edit. Only on iOS, Android.
    placeholderstring--Native only: hint text shown while the field is empty. On web it is the placeholder attribute. Only on iOS, Android.

    Anatomy

    PartDescription
    rootThe textarea element: raised fill, light edge, radius-container, 14px text at body leading (16px on touch, so iOS doesn't zoom). Never shorter than size-element-* of its size.
    placeholderHint text shown when the value is empty. Colored with text-secondary, so it reaches 4.5:1 on the raised fill.
    groupThe field box when showCount is set: a wrapper with the textarea's fill, border, radius and padding, showing its focus, disabled look and danger border through :has(). className lands here.
    countThe character count at the bottom end of the group, in mono xs text-tertiary with tabular figures.

    Accessibility

    Role: textbox

    KeysAction
    TabMoves focus in and out of the textarea; inside it, Tab is not captured.
    EnterStarts a new line. It never submits the form.
    • Name it with a visible label. Inside a Field, FieldLabel points at it and FieldControl links its description and error.
    • A placeholder is a hint, not a label: it disappears as soon as the user types.
    • aria-invalid shows the danger border; pair it with error text, since the border alone relies on color. A FieldError does both.
    • A textarea is a replaced element, so it has no ::before hit area. It is never shorter than a control of its size.
    • Disabled text can still scroll, so nothing in a long value is lost from view.

    Install

    npx werewolf-ui add textarea

    Run npx werewolf-ui init once in your app before adding components. Init sets up tokens, their CSS import and agent rules. Add installs this component and its dependencies while preserving your theme. See Installation for requirements and the alternative registry setup.