Components / Forms

Textarea23

The multi-line sibling of Input: same label, help text, errors and focus lift, for messages, notes and anything longer than a line. It can grow as you type.

Textarea · PlaygroundLive
JSX
<Textarea label="Message" placeholder="Say hello…" />

Usage

TSX
import { Textarea } from "plonk-ui";

export function Feedback() {
  return <Textarea label="Message" name="message" rows={4} />;
}

Textarea renders a real <textarea> and passes every native prop to it: value and onChange, defaultValue, maxLength, rows, ref. className styles the outer wrapper. description and error work exactly like they do on Input, and so does validation.

Growing with the text

autoResize makes the field as tall as its content, up to 20rem, and then it scrolls. It uses CSS field-sizing; in browsers without it, the field keeps a fixed height that people can resize by hand.

Textarea · Auto resizeLive

Grows as you type, then scrolls.

TSX
import { Textarea } from "plonk-ui";

export default function AutoResize() {
  return (
    <Textarea
      className="w-full max-w-sm"
      label="Release notes"
      description="Grows as you type, then scrolls."
      autoResize
      rows={2}
      defaultValue={"Buttons now press harder.\nToasts peel off the corner."}
    />
  );
}

Character count

Control the value and put the count in description. It sits under the field and is read along with the label. maxLength stops typing at the limit.

Textarea · Character countLive

98 characters left

TSX
import { useState } from "react";
import { Textarea } from "plonk-ui";

const LIMIT = 140;

export default function Count() {
  const [bio, setBio] = useState("Frontend developer. I make buttons squish.");
  const left = LIMIT - bio.length;

  return (
    <Textarea
      className="w-full max-w-sm"
      label="Bio"
      value={bio}
      onChange={(event) => setBio(event.target.value)}
      maxLength={LIMIT}
      description={`${left} characters left`}
    />
  );
}

Personalities

The field lifts on focus in Sticker, Comic and Retro, and lights a neon ring in Arcade, just like Input. Errors stick on as a tilted tag and shake the field once.

Accessibility

  • The label is a real <label> linked to the field. Without one, pass aria-label.
  • description and error are linked with aria-describedby; error also sets aria-invalid.
  • Tab moves out of the field; Enter adds a new line and never submits the form.
  • Screen readers don't repeat the description while you type. For a limit that matters, also check it when the form is submitted.

API

All other <textarea> props are passed through.

PropTypeDefaultDescription
autoResizebooleanfalseGrows with its content (field-sizing: content) up to 20rem, then scrolls. Browsers without support keep a resizable field.
labelReactNode—Visible label, linked to the control. Without one, pass aria-label or aria-labelledby.
descriptionReactNode—Help text under the control, read by screen readers after the label.
errorReactNode—Error message. When set, the control is marked invalid (aria-invalid) and shakes once. Pass true to mark it without a message.
rowsnumber3Starting height in lines.
namestring—Field name in the submitted form data.
requiredboolean—Marks the field required, with an asterisk in the label.
disabledboolean—Disables the field. The border turns dashed.