# Textarea

A multi-line field in a drawn box that grows with its text, optionally on ruled lines.

Docs: https://ballpoint.st9wd.com/docs/textarea

```bash
npx shadcn@latest add @ballpoint/textarea
```

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

<Textarea placeholder="Write something." />
```

Props:

- `variant`: `"box" | "lined"` (default `"box"`). A drawn box, or one with ruled lines to write on.
- `className`: `string`. Styles the drawn box. Every other prop goes to the <textarea>.
- `seed`: `string | number`. Pins the drawing.

Pen settings: `draw`, `roughness`, `passes`, `radius`, `corners`, `weight`, `speed` (see Pen settings).

## Example

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

export default function TextareaDemo() {
  return (
    <div className="grid w-full max-w-lg gap-6">
      <div className="grid gap-2">
        <Label htmlFor="textarea-message">Message</Label>
        <Textarea id="textarea-message" placeholder="It grows as you write." seed="textarea-message" />
      </div>
      <div className="grid gap-2">
        <Label htmlFor="textarea-notes">Notes, on ruled lines</Label>
        <Textarea id="textarea-notes" variant="lined" rows={4} defaultValue={"Buy ink.\nCall the printer about the cream stock."} seed="textarea-notes" />
      </div>
    </div>
  );
}
```

## Character count

A live count that turns red when the note runs over.

```tsx
"use client";

import { useState } from "react";
import { Field, FieldLabel } from "@/components/ui/field";
import { Textarea } from "@/components/ui/textarea";

const LIMIT = 120;

export default function TextareaCounter() {
  const [text, setText] = useState("Dear Ada, the ink arrived.");
  const over = text.length > LIMIT;
  return (
    <Field className="w-full max-w-lg" data-invalid={over || undefined}>
      <FieldLabel htmlFor="tc-note">Postcard</FieldLabel>
      <Textarea id="tc-note" value={text} onChange={(e) => setText(e.target.value)} aria-invalid={over} aria-describedby="tc-count" seed="tc-note" />
      <p id="tc-count" className={over ? "text-sm text-destructive" : "text-sm text-ink-3"}>
        {text.length} / {LIMIT}
        {over && " – too long for a postcard"}
      </p>
    </Field>
  );
}
```

## States

Invalid with a message, read-only and disabled.

```tsx
import { Field, FieldDescription, FieldError, FieldLabel } from "@/components/ui/field";
import { Textarea } from "@/components/ui/textarea";

export default function TextareaStates() {
  return (
    <div className="grid w-full max-w-lg gap-6">
      <Field data-invalid>
        <FieldLabel htmlFor="ts-invalid">Message</FieldLabel>
        <Textarea id="ts-invalid" aria-invalid placeholder="Say something." seed="ts-invalid" />
        <FieldError>A message can&apos;t be empty.</FieldError>
      </Field>
      <Field>
        <FieldLabel htmlFor="ts-readonly">Read-only</FieldLabel>
        <Textarea id="ts-readonly" readOnly defaultValue="This note is locked in the archive." seed="ts-readonly" />
        <FieldDescription>Select and copy it, but it won&apos;t change.</FieldDescription>
      </Field>
      <Field data-disabled>
        <FieldLabel htmlFor="ts-disabled">Disabled</FieldLabel>
        <Textarea id="ts-disabled" disabled placeholder="Waiting for the pen." seed="ts-disabled" />
      </Field>
    </div>
  );
}
```

## With a button

A message field with its send button.

```tsx
"use client";

import { Button } from "@/components/ui/button";
import { Field, FieldLabel } from "@/components/ui/field";
import { Textarea } from "@/components/ui/textarea";

export default function TextareaWithButton() {
  return (
    <form onSubmit={(event) => event.preventDefault()} className="flex w-full max-w-lg flex-col gap-4">
      <Field>
        <FieldLabel htmlFor="twb-message">Your message</FieldLabel>
        <Textarea id="twb-message" placeholder="Type your message here." seed="twb-message" />
      </Field>
      <Button type="submit" className="self-end" seed="twb-send">
        Send message
      </Button>
    </form>
  );
}
```

## Pen settings

- `draw`: `"auto" | "mount" | "none"` (default `"auto"`). When the strokes draw themselves in: the first time they scroll into view, as soon as they render, or never (already drawn).
- `roughness`: `number` (default `1`). 0 is ruler-neat, 1 a quick confident hand, 2 a scrawl.
- `passes`: `1 | 2 | 3`. How many times an outline is gone over. Each component picks its own default.
- `radius`: `number | "full"` (default `0`). Corner radius in px; "full" draws a pill.
- `corners`: `"crossed" | "joined"` (default `"crossed"`). Square corners: sides pulled separately past each other, or the box drawn in one motion.
- `weight`: `number` (default `1`). Line weight multiplier. Also settable in CSS as --ink-weight.
- `speed`: `number` (default `1`). Drawing speed multiplier. Also settable in CSS as --ink-speed.
