# Textarea

> A multi-line text field.

A textarea takes text that runs over several lines, such as notes or a description, and grows with its content.

## When to use

- Use it for notes, descriptions and messages.
- Use an Input for one line, such as a name or a title.
- Put it in a Field, with a hint that says the limit, such as "Paling banyak 500 karakter."

_Live preview of the React and Vue versions: https://design.sosialoka.tech/components/textarea/_

## Anatomy

1. Label
2. Field that grows with its text
3. Resize handle

A box on `radius-md` with an `input` border, at least `min-h-16` tall, that grows with its content (`field-sizing-content`). Focus shows the `ring`; an invalid value turns the border `destructive`.

## Variants

There is one style.

## Props

| React | Vue | Flutter | Type | Default | Use |
| --- | --- | --- | --- | --- | --- |
| `value` / `defaultValue` | `v-model` / `default-value` | `controller` / `initialValue` | text | none | The text. |
| `maxLength` | `maxlength` | `maxLength` | number | none | The longest text allowed. Say it in the hint too. |
| `rows` | `rows` | `minHeight` | number | grows with content | The starting height. |
| `aria-invalid` | `aria-invalid` | `forceErrorText` on `ShadTextareaFormField` | boolean | `false` | Marks a refused value. |
| `disabled` | `disabled` | `enabled: false` | boolean | `false` | Blocks typing. |

## Code

**React**
```tsx
import { useId } from "react"
import { Field, FieldDescription, FieldLabel } from "@/components/ui/field"
import { Textarea } from "@/components/ui/textarea"

export default function TextareaDemo() {
  const id = useId()
  return (
    <Field className="w-full max-w-sm">
      <FieldLabel htmlFor={`${id}-notes`}>Catatan untuk tim</FieldLabel>
      <Textarea id={`${id}-notes`} maxLength={500} aria-describedby={`${id}-notes-hint`} />
      <FieldDescription id={`${id}-notes-hint`}>Paling banyak 500 karakter.</FieldDescription>
    </Field>
  )
}
```

**Vue**
```vue
<script setup lang="ts">
import { useId } from "vue"
import { Field, FieldDescription, FieldLabel } from "@/components/ui/field"
import { Textarea } from "@/components/ui/textarea"

const id = useId()
</script>

<template>
  <Field class="w-full max-w-sm">
    <FieldLabel :for="`${id}-notes`">Catatan untuk tim</FieldLabel>
    <Textarea :id="`${id}-notes`" :maxlength="500" :aria-describedby="`${id}-notes-hint`" />
    <FieldDescription :id="`${id}-notes-hint`">Paling banyak 500 karakter.</FieldDescription>
  </Field>
</template>
```

**Flutter**
```dart
import 'package:flutter/widgets.dart';
import 'package:shadcn_ui/shadcn_ui.dart';

class TextareaDemo extends StatelessWidget {
  const TextareaDemo({super.key});

  @override
  Widget build(BuildContext context) {
    final theme = ShadTheme.of(context);
    // ShadTextareaFormField does not pass maxLength on, so the label and hint sit around a ShadTextarea.
    return ConstrainedBox(
      constraints: const BoxConstraints(maxWidth: 384),
      child: Column(
        mainAxisSize: MainAxisSize.min,
        crossAxisAlignment: CrossAxisAlignment.start,
        spacing: 8,
        children: [
          Text('Catatan untuk tim', style: theme.textTheme.small),
          const ShadTextarea(maxLength: 500),
          Text('Paling banyak 500 karakter.', style: theme.textTheme.muted),
        ],
      ),
    );
  }
}
```

## Install

**React**
```bash
npx shadcn@latest add https://design.sosialoka.tech/r/react/textarea.json
```

**Vue**
```bash
npx shadcn-vue@latest add https://design.sosialoka.tech/r/vue/textarea.json
```

## Accessibility

- Give it a visible label in a Field.
- Tie the hint and any error to it with `aria-describedby`.
- It keeps the native `textarea` keyboard behavior: Enter adds a line, Tab moves on.
