# Textarea

A field for longer text that runs over several lines.

```tsx
import { TextareaField } from '@halo-ds/react';
```

## When to use it
Use a Textarea for answers longer than a line: messages, comments, descriptions and feedback. It matches the Input in states, colours and tokens, and grows taller when people need more room. Wrap it in a Textarea field for a label, a hint and a character count. For a single line, like a name or an email, use an Input.

## Do
- Size the box to the answer you expect: taller for feedback, shorter for a bio.
- Show a character count when there is a limit, from the start.
- Use the placeholder for an example, and the label for the question.
- Let people keep typing past the limit, then show the error.

## Don't
- Use a Textarea for one-line answers; use an Input.
- Cut off what people type at the limit without telling them.
- Make the box so small that people cannot see what they wrote.
- Turn off the resize handle unless the box grows by itself.

## Textarea or Input?
Pick by how long the answer is likely to be.
- **Input**: One line: names, emails, titles, search.
- **Textarea**: Several lines: messages, comments, descriptions and feedback.

## Props
### TextareaField props
| Prop | Type | What it does |
| --- | --- | --- |
| `showCount` | `boolean \| undefined` | Shows "used / maxLength" under the box when maxLength is set. Figma: Count. |
| `fieldClassName` | `string \| undefined` |  |
| `fieldClassNames` | `Partial<Record<FieldPart, string>> \| undefined` |  |
| `fieldStyles` | `Partial<Record<FieldPart, CSSProperties>> \| undefined` |  |
| `size` | `"sm" \| "md" \| "lg" \| undefined` | Text size and padding. Figma: Size. |
| `resize` | `boolean \| undefined` | Lets people drag the corner to make it taller. Figma: Resize handle. |
| `invalid` | `boolean \| undefined` |  |
| `classNames` | `Partial<Record<TextareaPart, string>> \| undefined` | Extra class names for the parts inside the component, by part name, like `{ header: 'my-header' }`. |
| `styles` | `Partial<Record<TextareaPart, CSSProperties>> \| undefined` | Inline styles for the parts inside the component, by part name, like `{ footer: { gap: 4 } }`. |
| `label` | `ReactNode` |  |
| `error` | `ReactNode` | An error message. Replaces the hint, turns red and marks the control invalid. The control shows the warning icon, so the message has none. Figma: State=Error. |
| `hint` | `ReactNode` | Help text under the control. Figma: Hint. |
| `optional` | `boolean \| undefined` |  |
| `info` | `ReactNode` |  |
It also takes the usual HTML attributes for its element.

## Examples
### Overview
```tsx
import { TextareaField } from '@halo-ds/react';

export default function Example() {
  return (
    <div style={{ width: 360 }}>
      <TextareaField label="Message" placeholder="Write your message" maxLength={280} hint="Keep it short." />
    </div>
  );
}
```

### States
An error with a message that says what to do, and disabled.
```tsx
import { TextareaField } from '@halo-ds/react';

export default function Demo() {
  return (
    <div className="demo-stack" style={{ width: 360 }}>
      <TextareaField label="Bio" placeholder="A sentence or two about you" error="Add a few words about yourself." />
      <TextareaField label="Notes" placeholder="Anything we should know" disabled defaultValue="Read only for now." />
    </div>
  );
}
```

More: https://halodesignsystem.dev/components/textarea
