# Textarea

Several lines of text in the same box and states as Input, at least 80 px tall. Built on ui-sdk's Textarea: it can grow with its text and submit on a shortcut.

- Beta: ready to use; its API can still change in a minor release.
- Category: Form fields

```tsx
import { Field, Textarea } from "@leap-crm/design-system";
```

## Best practices

- Do: Use it for text that runs over several lines, like a file note or a matter's description. Use `Input` for one line, like a name or an email.
- Do: Set `autoResize` with a `max-h-*` class for notes that vary in length, so a short note stays short and a long one stops at the height you set.
- Do: Put it in a `Field` with a `CharacterCount` in `counter` when the text has a limit, and set `showFrom` near the limit so the count only appears when it matters.
- Do: Set `submitShortcut` to `mod+enter` with `onSubmit` for a quick reply or comment. Enter still starts a new line.
- Don't: Use it when the text needs bold, lists or links. Use `RichTextField` around the CRM's editor.

## Keyboard

| Keys | What they do |
| --- | --- |
| Enter | Starts a new line; with the enter submit shortcut, submits the form instead. |
| Shift + Enter | With the enter submit shortcut, starts a new line. |
| Ctrl + Enter, ⌘ + Enter | With the mod+enter submit shortcut, submits the form. |

## Related

- [Input](./input.md)
- [Rich Text Field](./rich-text-field.md)
- [Field](./field.md)

## Examples

What the examples import:

```tsx
import { useState } from "react";
import { CharacterCount, Field, Textarea } from "@leap-crm/design-system";
```

Scaffolding the examples call. It lives in the docs page, not in the library:

```tsx
function CounterDemo() {
  const [note, setNote] = useState("Prefers email. Settlement due in March.");
  return (
    <div className="w-80">
      <Field
        label="Notes"
        hint="Visible to everyone at the firm."
        counter={
          <CharacterCount length={note.length} max={280} showFrom={200} />
        }
      >
        <Textarea value={note} onValueChange={setNote} maxLength={280} />
      </Field>
    </div>
  );
}
```

### In a field

With a label, a hint and a counter that appears near the limit.

```tsx
<CounterDemo />
```

### Grows with its text

autoResize grows the box line by line; max-h-40 stops it at 160 px, then it scrolls. Mod+Enter submits.

```tsx
<div className="w-80">
  <Field label="Reply">
    <Textarea
      autoResize
      submitShortcut="mod+enter"
      onSubmit={() => undefined}
      className="max-h-40"
      placeholder="Write a reply"
    />
  </Field>
</div>
```

### States

Hover darkens the edge; Tab in to see focus, blue or red when invalid. Read-only takes the subtle surface, disabled dims to 50%.

```tsx
<div className="grid w-full max-w-2xl grid-cols-2 gap-x-6 gap-y-6">
  <Field label="Default">
    <Textarea defaultValue="Prefers email. Settlement due in March." />
  </Field>
  <Field label="Error" error="Please add a note">
    <Textarea />
  </Field>
  <Field label="Read-only">
    <Textarea
      defaultValue="Prefers email. Settlement due in March."
      readOnly
      copyable
    />
  </Field>
  <Field label="Disabled" disabled>
    <Textarea defaultValue="Prefers email. Settlement due in March." />
  </Field>
</div>
```

## Props

Also takes every native textarea prop and ui-sdk's value, defaultValue, onValueChange, autoResize, onSubmit and submitShortcut.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `clearable` | `boolean` | `false` | Shows a × that empties the field while it holds text. |
| `copyable` | `boolean` | `false` | Shows a button that copies the text. |
| `className` | `string` |  | Classes for the box around the text, which draws the edge and the states. |
| `autoResize` | `unknown` | `false` |  |
