# Textarea

A multiline text field that grows with its text.

A multiline text field that grows with its text: a comment, a description, a commit message. It is Input's multiline field (72px minimum; the shared control's sizes, looks, rings, hover and motion, through the input recipe) on Ark UI's Field.Textarea with autoresize. A max-height class caps the growth; past it the text scrolls. Inside a Field it is wired to the label, helper and error.

Kind: component · Category: Inputs · Status: beta · Targets: React, Vue, Svelte · Behaviour: Zag `field` machine, through Ark UI

## Add

```bash
npx fndn add textarea
```

It writes the folder `textarea/` into the project's ui folder (`index.ts`, `textarea.tsx`, `Textarea.vue`, `Textarea.svelte`, `textarea.recipe.ts`), and what it is built from: [Input](/components/input.md). First time: [Installation](/installation.md).

## Usage

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

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

```svelte
import { Textarea } from "$lib/components/ui/textarea";
```

## Parts

In the DOM the root carries `data-slot="textarea"` and each part `data-slot="textarea-<part>"`; in the recipe the root is the `base` slot and each part a slot named after it in camelCase.

| Part | Element | data-slot | Flags | Notes |
| --- | --- | --- | --- | --- |
| `root` | `textarea` | `textarea` |  | The <textarea> itself (class and style land on it): 72px minimum, then as tall as its text; dir="auto" so the text keeps its own direction while the alignment follows the page. |

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `value` | `string` |  | Bindable (React: `defaultValue` and `onValueChange`; Vue: `v-model:value`; Svelte: `bind:value`). Controlled: value with onChange. Uncontrolled: defaultValue. |
| `size` | `"xs" \| "sm" \| "md" \| "lg"` | `"md"` | The shared control's sizes (`lib/control.ts`): text and padding of xs, sm, md, lg (12 · 12 · 13 · 14px; 6 · 8 · 10 · 12px); the block padding centres one line in the size's height. Every size starts at 72px. |
| `variant` | `"outline" \| "subtle" \| "ghost"` | `"outline"` | The shared control's looks (`lib/control.ts`), at every size. outline: the form field (field colour, hairline). subtle: the inspector (inset grey, no edge). ghost: nothing until touched. Focused, open and invalid look the same in every variant. |
| `mono` | `boolean` | `false` |  |
| `invalid` | `boolean` | `false` | The red ring (aria-invalid). Inside a Field, the Field's invalid. |
| `autoResize` | `boolean` | `true` | Grow with the text (no resize handle). false: a fixed 72px field with a vertical resize handle. |
| `disabled` | `boolean` | `false` |  |
| `placeholder` | `string` |  |  |
| `rows` | `number` |  | Starting height in lines, when taller than 72px. |

Other attributes and `class` go to the root; `class` is merged through the recipe.

## Events

| Event | Payload |
| --- | --- |
| `input` | (value: string): the native input event |

## States

`hover`, `focus`, `invalid`, `disabled`

## Keyboard and accessibility

Keyboard:

- Standard text editing; Enter adds a line; Tab moves on

Notes:

- Needs a name: a Field label or an aria-label.
- Text is 16px on touch devices so iOS does not zoom the page on focus.
- Its height follows the text; nothing moves on first paint (a long first value is sized before it).

## Motion

- the Input's: focus and invalid rings over duration.base; the hover fill over duration.fast (pointer only)
- growing is instant: the height follows each keystroke, never animated

## Tokens

`color.field`, `color.surface`, `color.hover`, `color.ink`, `color.ink-3`, `color.accent`, `color.accent-tint`, `color.red`, `color.red-tint`, `shadow.hairline`, `radius.control`, `text.xs`, `text.sm`, `font.mono`, `duration.fast`, `duration.base`

## Dependencies

- [Input](/components/input.md)

## Examples

### Comment on a pull request

React · `review-comment.tsx`

```tsx
import { useState } from "react";
import { Button } from "@/components/ui/button";
import { Textarea } from "@/components/ui/textarea";

/* starts at three lines and grows a line at a time as you type */
export default function ReviewComment() {
  const [comment, setComment] = useState("");
  return (
    <div className="flex w-full max-w-80 flex-col gap-2">
      <Textarea
        aria-label="Comment on #482 Add retry to webhook delivery"
        placeholder="Leave a comment"
        value={comment}
        onChange={(event) => setComment(event.target.value)}
      />
      <div className="flex justify-end gap-2">
        <Button size="sm" variant="secondary" onClick={() => setComment("")}>Cancel</Button>
        <Button size="sm" variant="primary" disabled={comment.trim() === ""}>Comment</Button>
      </div>
    </div>
  );
}
```

Vue · `review-comment.vue`

```vue
<script setup lang="ts">
import { ref } from "vue";
import { Button } from "@/components/ui/button";
import { Textarea } from "@/components/ui/textarea";

const comment = ref("");
</script>

<!-- starts at three lines and grows a line at a time as you type -->
<template>
  <div class="flex w-full max-w-80 flex-col gap-2">
    <Textarea
      v-model:value="comment"
      aria-label="Comment on #482 Add retry to webhook delivery"
      placeholder="Leave a comment"
    />
    <div class="flex justify-end gap-2">
      <Button size="sm" variant="secondary" @click="comment = ''">Cancel</Button>
      <Button size="sm" variant="primary" :disabled="comment.trim() === ''">Comment</Button>
    </div>
  </div>
</template>
```

Svelte · `review-comment.svelte`

```svelte
<script lang="ts">
  import { Button } from "$lib/components/ui/button";
  import { Textarea } from "$lib/components/ui/textarea";

  let comment = $state("");
</script>

<!-- starts at three lines and grows a line at a time as you type -->
<div class="flex w-full max-w-80 flex-col gap-2">
  <Textarea
    bind:value={comment}
    aria-label="Comment on #482 Add retry to webhook delivery"
    placeholder="Leave a comment"
  />
  <div class="flex justify-end gap-2">
    <Button size="sm" variant="secondary" onclick={() => (comment = "")}>Cancel</Button>
    <Button size="sm" variant="primary" disabled={comment.trim() === ""}>Comment</Button>
  </div>
</div>
```

### Release notes, capped height

React · `release-notes.tsx`

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

const notes =
  "Usage alerts: owners get an email at 80% and 100% of the monthly limit.\nWebhook delivery retries up to 5 times with backoff (#482).\nInvoices show the VAT number when one is set.\nThe members page loads 3x faster on large workspaces.\nFixed: preview deploys of forks no longer read production secrets.\nFixed: the CLI kept a stale token after sign-out.\nDeprecated: the v1 deploys endpoint stops on Jan 31, 2027.";

/* a max-height caps the growth; past it the text scrolls */
export default function ReleaseNotes() {
  return <Textarea aria-label="Release notes for web-app v2.14" className="max-h-40 w-full max-w-80" defaultValue={notes} />;
}
```

Vue · `release-notes.vue`

```vue
<script setup lang="ts">
import { ref } from "vue";
import { Textarea } from "@/components/ui/textarea";

const notes = ref(
  "Usage alerts: owners get an email at 80% and 100% of the monthly limit.\nWebhook delivery retries up to 5 times with backoff (#482).\nInvoices show the VAT number when one is set.\nThe members page loads 3x faster on large workspaces.\nFixed: preview deploys of forks no longer read production secrets.\nFixed: the CLI kept a stale token after sign-out.\nDeprecated: the v1 deploys endpoint stops on Jan 31, 2027.",
);
</script>

<!-- a max-height caps the growth; past it the text scrolls -->
<template>
  <Textarea v-model:value="notes" aria-label="Release notes for web-app v2.14" class="max-h-40 w-full max-w-80" />
</template>
```

Svelte · `release-notes.svelte`

```svelte
<script lang="ts">
  import { Textarea } from "$lib/components/ui/textarea";

  let notes = $state(
    "Usage alerts: owners get an email at 80% and 100% of the monthly limit.\nWebhook delivery retries up to 5 times with backoff (#482).\nInvoices show the VAT number when one is set.\nThe members page loads 3x faster on large workspaces.\nFixed: preview deploys of forks no longer read production secrets.\nFixed: the CLI kept a stale token after sign-out.\nDeprecated: the v1 deploys endpoint stops on Jan 31, 2027.",
  );
</script>

<!-- a max-height caps the growth; past it the text scrolls -->
<Textarea bind:value={notes} aria-label="Release notes for web-app v2.14" class="max-h-40 w-full max-w-80" />
```

### Webhook payload, resizable

React · `webhook-payload.tsx`

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

const payload = '{\n  "event": "deploy.failed",\n  "project": "billing-api",\n  "deploy": "dpl_7f3a9c",\n  "commit": "a1b2c3d"\n}';

/* autoResize off: a fixed height with a resize handle; mono for code */
export default function WebhookPayload() {
  return <Textarea autoResize={false} rows={6} mono aria-label="Test payload" className="w-full max-w-80" defaultValue={payload} />;
}
```

Vue · `webhook-payload.vue`

```vue
<script setup lang="ts">
import { ref } from "vue";
import { Textarea } from "@/components/ui/textarea";

const payload = ref('{\n  "event": "deploy.failed",\n  "project": "billing-api",\n  "deploy": "dpl_7f3a9c",\n  "commit": "a1b2c3d"\n}');
</script>

<!-- autoResize off: a fixed height with a resize handle; mono for code -->
<template>
  <Textarea v-model:value="payload" :auto-resize="false" :rows="6" mono aria-label="Test payload" class="w-full max-w-80" />
</template>
```

Svelte · `webhook-payload.svelte`

```svelte
<script lang="ts">
  import { Textarea } from "$lib/components/ui/textarea";

  let payload = $state('{\n  "event": "deploy.failed",\n  "project": "billing-api",\n  "deploy": "dpl_7f3a9c",\n  "commit": "a1b2c3d"\n}');
</script>

<!-- autoResize off: a fixed height with a resize handle; mono for code -->
<Textarea bind:value={payload} autoResize={false} rows={6} mono aria-label="Test payload" class="w-full max-w-80" />
```

### Reason for cancelling

React · `cancel-reason.tsx`

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

export default function CancelReason() {
  return (
    <Field label="Why are you cancelling?" helper="Optional. Read by the billing team, never shared." className="w-full max-w-80">
      <Textarea placeholder="Missing a feature, too expensive, moving to another tool…" />
    </Field>
  );
}
```

Vue · `cancel-reason.vue`

```vue
<script setup lang="ts">
import { ref } from "vue";
import { Field } from "@/components/ui/field";
import { Textarea } from "@/components/ui/textarea";

const reason = ref("");
</script>

<template>
  <Field label="Why are you cancelling?" helper="Optional. Read by the billing team, never shared." class="w-full max-w-80">
    <Textarea v-model:value="reason" placeholder="Missing a feature, too expensive, moving to another tool…" />
  </Field>
</template>
```

Svelte · `cancel-reason.svelte`

```svelte
<script lang="ts">
  import { Field } from "$lib/components/ui/field";
  import { Textarea } from "$lib/components/ui/textarea";

  let reason = $state("");
</script>

<Field label="Why are you cancelling?" helper="Optional. Read by the billing team, never shared." class="w-full max-w-80">
  <Textarea bind:value={reason} placeholder="Missing a feature, too expensive, moving to another tool…" />
</Field>
```

## Recipe

`textarea.recipe.ts`:

```ts
import { tv, type VariantProps } from "../lib/tv";
import { input } from "../input/input.recipe";
import { control, controlSize, controlVariant } from "../lib/control";

/* textarea — Input's multiline field as a component of its own, growing with its text (Ark UI's
 * Field.Textarea with autoresize). Every class is the input recipe's (multiline: 72px minimum,
 * 1.5 leading, the block padding that centres one line in the size's height; the shared control's
 * sizes, looks, rings, hover and motion: lib/control.ts), so the two never drift; only what a
 * textarea adds is written here.
 *
 * Auto-grow: the engine sets the height from the content on every change; a max-height from the
 * caller (max-h-40) caps it and the text scrolls past it. The resize handle goes while it grows. */

/* the input recipe's md outline multiline field, without its font-family choice (the mono variant
 * below makes it, as input.recipe.ts does); size and variant below replace the md and outline classes */
const md = input({ multiline: true, size: "md" })
  .base()
  .split(" ")
  .filter((c) => c !== "[font-family:inherit]")
  .join(" ");

export const textarea = tv({
  /* the control first (what it is made of), then the multiline field, which wins where they differ
   * (h-auto, the 72px minimum) */
  base: [control({ kind: "field" }).base(), md],
  variants: {
    /* the shared control's sizes and the input recipe's multiline padding for each (input.recipe.ts) */
    size: {
      xs: [controlSize.xs, "py-[3px]"],
      sm: [controlSize.sm, "py-[5px]"],
      md: [controlSize.md, "py-[7px]"],
      lg: [controlSize.lg, "py-2"],
    },
    variant: {
      outline: controlVariant.outline,
      subtle: controlVariant.subtle,
      ghost: controlVariant.ghost,
    },
    mono: {
      true: "font-mono",
      false: "[font-family:inherit]",
    },
    autoResize: {
      true: "resize-none",
      false: "",
    },
  },
  defaultVariants: { size: "md", variant: "outline", mono: false, autoResize: true },
});

export type TextareaRecipeProps = VariantProps<typeof textarea>;
```
