# Textarea

A multi-line text field with resize control and validation.

## Label and value

A label sits above, tied to the field by its `id`. `bind:value` keeps a state in step with the field.

## Resize

`resize` sets which way the corner drags: vertical by default, or none, horizontal or both.

## Validation

`required` and `maxlength` are the browser's: submit it empty, or past 280 characters, and the browser stops it. `invalid` marks the field for any other error; the message under it is linked by `aria-describedby`.

## Disabled and readonly

A disabled field is out of the form; a readonly one is submitted and can be selected, not changed.

## Examples

```svelte
<script lang="ts">
  import Button from '@qualia-studios/design-ui/components/Button.svelte';
  import Textarea from '@qualia-studios/design-ui/components/Textarea.svelte';

  let bio = $state('');
  let feedback = $state('');
  const MAX = 280;
  let submitted = $state(false);
</script>
```

### Example 1: A labelled field

```svelte
<div class="col">
  <label for="default">Description</label>
  <Textarea id="default" placeholder="Tell us more…" />
</div>
```

### Example 2: A bound field

```svelte
<div class="col">
  <label for="bio">Bio</label>
  <Textarea
    id="bio"
    placeholder="A few sentences about you"
    bind:value={bio}
  />
  <small>Length: <code>{bio.length}</code></small>
</div>
```

### Example 3: Resize vertical and none

```svelte
<div class="grid">
  <div class="col">
    <label for="rv">Vertical (default)</label>
    <Textarea id="rv" />
  </div>
  <div class="col">
    <label for="rn">None</label>
    <Textarea id="rn" resize="none" />
  </div>
</div>
```

### Example 4: Resize horizontal and both

```svelte
<div class="grid">
  <div class="col">
    <label for="rh">Horizontal</label>
    <Textarea id="rh" resize="horizontal" />
  </div>
  <div class="col">
    <label for="rb">Both</label>
    <Textarea id="rb" resize="both" />
  </div>
</div>
```

### Example 5: Browser validation

Submit it empty, or past the character limit.

```svelte
<form
  class="col"
  onsubmit={(e) => {
    e.preventDefault();
    submitted = true;
  }}
>
  <label for="feedback">Feedback</label>
  <Textarea
    id="feedback"
    name="feedback"
    maxlength={MAX}
    required
    bind:value={feedback}
    aria-describedby="feedback-count"
  />
  <small id="feedback-count" class="count">
    {feedback.length}/{MAX}
  </small>
  <Button type="submit" class="primary small">Send</Button>
  {#if submitted}
    <small>Sent!</small>
  {/if}
</form>
```

### Example 6: An invalid field

```svelte
<div class="col">
  <label for="invalid">Notes</label>
  <Textarea
    id="invalid"
    invalid
    value="Something's off here"
    aria-describedby="invalid-msg"
  />
  <small id="invalid-msg" class="error"
    >This note exceeds policy length.</small
  >
</div>
```

### Example 7: Disabled and readonly

```svelte
<div class="col">
  <label for="disabled">Disabled</label>
  <Textarea id="disabled" value="cannot edit" disabled />
  <label for="readonly">Readonly</label>
  <Textarea id="readonly" value="read only value" readonly />
</div>
```

---

From the Qualia design guide: https://q-core-3b2732.gitlab.io/components/textarea. Every page as markdown: https://q-core-3b2732.gitlab.io/llms.txt
