# Textarea

> Multi-line text field with the same finish as the input, resizable vertically or growing with its content.

- Kind: ui · Category: Forms · Interactivity: native
- Install: `npx shadcn@latest add @haze/textarea`
- File: `src/components/haze/ui/textarea.astro`
- npm dependencies: none
- Registry dependencies: @haze/utils
- Docs page: https://hazeui.com/ui/textarea

## Use when
- Messages, comments, bios and release notes that run past one line
- Contact forms where the user explains a problem in their own words

## Avoid when
- Short single-line values such as an email; use input
- Rich text with formatting, which needs an editor

## Alternatives
- [input](https://hazeui.com/ui/input.md)
- [field](https://hazeui.com/ui/field.md)

## Props

| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| id | `string` |  | yes | Element id; reference it from a label or Field. |
| name | `string` | id | no | Form field name. |
| rows | `number` | 4 | no | Visible lines before the user resizes it. |
| placeholder | `string` |  | no | Example text shown while empty. |
| autoGrow | `boolean` | false | no | Grows the box with its content up to 15 rem where the browser supports field-sizing, and turns off manual resizing. |
| required | `boolean` |  | no | Marks the field required. |
| class | `string` |  | no | Extra classes. |
| ...rest | `attributes` |  | no | Any other textarea attribute: disabled, maxlength, aria-invalid, aria-describedby. |

## Accessibility
- With autoGrow the box has no resize handle and stops growing at 15 rem, then scrolls; browsers without field-sizing keep the fixed rows height.
- Resizing is limited to the vertical axis so a dragged box cannot push the form past a 320 px viewport.
- The component renders no label; pair it with Field or a label whose for matches the id.
- aria-invalid turns the border destructive, but also add an error message so the state is not shown by color alone.
- Key Enter: Inserts a new line instead of submitting the form
- Key Tab: Moves focus out of the field

## Agent prompts

### Install and use

Install the Haze UI component "Textarea" with `npx shadcn@latest add @haze/textarea`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "https://hazeui.com/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import Textarea from "@/components/haze/ui/textarea.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: https://hazeui.com/ui/textarea.md

### Customize with real content

Adapt the Haze textarea ui for our product. Replace the demo values of these props with our real content: id, name, rows, placeholder, autoGrow, required, class, ...rest. Keep the layout, the heading level rules and these accessibility details: With autoGrow the box has no resize handle and stops growing at 15 rem, then scrolls; browsers without field-sizing keep the fixed rows height. Resizing is limited to the vertical axis so a dragged box cannot push the form past a 320 px viewport. The component renders no label; pair it with Field or a label whose for matches the id. aria-invalid turns the border destructive, but also add an error message so the state is not shown by color alone. Do not add raw color classes; use the Haze tokens.

### Choose the right block

Before using textarea, check it fits: use it when messages, comments, bios and release notes that run past one line; contact forms where the user explains a problem in their own words. Avoid it when short single-line values such as an email; use input; rich text with formatting, which needs an editor. Alternatives: @haze/input, @haze/field.

## Example requests that should lead here
- Add a message textarea under the email input in the contact form
- Show a textarea with an error under it when the reason is missing

## Source

```astro
---
import { cn } from "../../../lib/haze/utils";

interface Props {
  id: string;
  name?: string;
  rows?: number;
  placeholder?: string;
  /** Grows the box with its content, up to 15 rem, where the browser supports field-sizing. Turns off manual resizing. */
  autoGrow?: boolean;
  required?: boolean;
  class?: string;
  /** Any other textarea attribute, for example disabled, maxlength, aria-describedby or aria-invalid. */
  [key: string]: unknown;
}

const { id, name = id, rows = 4, placeholder, required, autoGrow = false, class: className, ...rest } = Astro.props;
---

<textarea
  id={id}
  name={name}
  rows={rows}
  placeholder={placeholder}
  required={required}
  class={cn(
    "min-h-20 w-full min-w-0 rounded-lg border border-frame-input bg-field px-3 py-2.5 text-sm/6 tracking-[-0.01em] text-foreground placeholder:text-muted-foreground",
    "transition-[border-color,background-color,box-shadow] duration-150 ease-snappy hover:border-frame-foreground",
    "focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/24 focus-visible:outline-hidden",
    "disabled:cursor-not-allowed disabled:bg-muted disabled:opacity-50 disabled:hover:border-frame-input aria-invalid:border-destructive! aria-invalid:focus-visible:ring-destructive/24",
    autoGrow ? "max-h-60 resize-none field-sizing-content" : "resize-y",
    className,
  )}
  {...rest}></textarea>
```
