> Leaf UI 0.17.3 · Package: @ifhover/leaf-ui · Source: c3221834f84f2f48481a2054026b713456f8e5dc
> Browser documentation: https://ifhover.github.io/leaf-ui/en/components/textarea.html

> For AI agents: the complete documentation index is available at https://ifhover.github.io/leaf-ui/en/llms.txt, the full documentation bundle is available at https://ifhover.github.io/leaf-ui/en/llms-full.txt.

# Textarea

Enter multiple lines of text, such as a message, description or note.


## Basic usage

Edit multiline text in the textarea and provide an associated field label.


Project description

basic.tsx

Copy code

```tsx lineNumbers file="../../../src/examples/en/textarea/basic.tsx"
import { Form, FormField, Textarea } from '@ifhover/leaf-ui';

export function TextareaBasic() {
  return (
    <Form layout="vertical">
      <FormField label="Project description">
        <Textarea name="description" placeholder="Describe your new idea" />
      </FormField>
    </Form>
  );
}
```

Expand code


## Examples

### States

Use `readOnly`, `disabled` or a `FormField` error to communicate field state.


Read only

Disabled

Error

Add a description.

states.tsx

Copy code

```tsx lineNumbers file="../../../src/examples/en/textarea/states.tsx"
import { Form, FormField, Textarea } from '@ifhover/leaf-ui';

export function TextareaStates() {
  return (
    <Form layout="vertical">
      <FormField label="Read only">
        <Textarea defaultValue="The public project description." readOnly />
      </FormField>
      <FormField label="Disabled">
        <Textarea placeholder="Currently unavailable" disabled />
      </FormField>
      <FormField label="Error" error="Add a description.">
        <Textarea placeholder="Add a description" />
      </FormField>
    </Form>
  );
}
```

Expand code

### Automatic height

`autoSize` adjusts height to the content. Bound the row count with `minRows` and `maxRows`; additional content scrolls inside the textarea.


Project description

auto-size.tsx

Copy code

```tsx lineNumbers file="../../../src/examples/en/textarea/auto-size.tsx"
import { Form, FormField, Textarea } from '@ifhover/leaf-ui';

export function TextareaAutoHeight() {
  return (
    <Form layout="vertical">
      <FormField label="Project description">
        <Textarea autoSize={{ minRows: 2, maxRows: 6 }} placeholder="Type more content" />
      </FormField>
    </Form>
  );
}
```

Expand code

### Character count

Set `showCount` to display the count and `maxLength` to limit input length.


Notes

21 / 120

count.tsx

Copy code

```tsx lineNumbers file="../../../src/examples/en/textarea/count.tsx"
import { Form, FormField, Textarea } from '@ifhover/leaf-ui';

export function TextareaCount() {
  return (
    <Form layout="vertical">
      <FormField label="Notes">
        <Textarea showCount maxLength={120} defaultValue="Start your plan here." />
      </FormField>
    </Form>
  );
}
```

Expand code

[](#)
### Controlled input

Manage content with `value` and `onChange`. The example derives its length hint from the current value.


Message

0 / 120

controlled.tsx

Copy code

```tsx lineNumbers file="../../../src/examples/en/textarea/controlled.tsx"
import { Form, FormField, Textarea } from '@ifhover/leaf-ui';
import { useState } from 'react';

export function TextareaControlled() {
  const [value, setValue] = useState('');
  return (
    <Form layout="vertical">
      <FormField label="Message" help={`${value.length} / 120`}>
        <Textarea
          value={value}
          maxLength={120}
          resize="none"
          placeholder="Up to 120 characters"
          onChange={(event) => setValue(event.target.value)}
        />
      </FormField>
    </Form>
  );
}
```

Expand code

#### Forms

Provide a name with `FormField` or `aria-label`. Set `name` for native form submission. Uncontrolled values support form reset; reset controlled values in application state. See [Form](https://ifhover.github.io/leaf-ui/en/components/form.md) for form integration.


## API

### Textarea API

Configure multiline text, length limits and input state.

| Property                 | Type                                                            | Default      | Description                                   |
| ------------------------ | --------------------------------------------------------------- | ------------ | --------------------------------------------- |
| `size`                   | `'sm' \| 'md' \| 'lg'`                                          | `'md'`       | Control size                                  |
| `status`                 | `'error' \| 'warning'`                                          | —            | Validation appearance                         |
| `rows`                   | `number`                                                        | `3`          | Initial visible rows                          |
| `resize`                 | `'none' \| 'vertical' \| 'both'`                                | `'vertical'` | Allowed manual resizing direction             |
| `value` / `defaultValue` | `string \| number \| readonly string[]`                         | —            | Controlled value / initial uncontrolled value |
| `onChange`               | `ChangeEventHandler<HTMLTextAreaElement>`                       | —            | Read event.target.value                       |
| `disabled` / `readOnly`  | `boolean`                                                       | `false`      | Disabled / read-only                          |
| `ref`                    | `Ref<HTMLTextAreaElement>`                                      | —            | DOM reference                                 |
| `autoSize`               | [`boolean \| TextareaAutoSize`](#textareaautosize-api)          | `false`      | Resize to content with optional row limits    |
| `showCount`              | `boolean \| ((value: string, maxLength?: number) => ReactNode)` | `false`      | Display count or a custom renderer            |

### TextareaAutoSize API

Limit the minimum and maximum rows used by automatic height adjustment.

| Property  | Type     | Default | Description  |
| --------- | -------- | ------- | ------------ |
| `minRows` | `number` | —       | Minimum rows |
| `maxRows` | `number` | —       | Maximum rows |
