# Text Area

## Usage

Use `TextArea` to enter multi-line plain text.

```vue
<script setup lang="ts">
import { TextArea } from '@astryx-vue/core/TextArea'
import { shallowRef } from 'vue'

const bio = shallowRef('')
</script>

<template>
  <TextArea v-model="bio" label="Bio" :rows="4" />
</template>
```

Import the theme once in the application entry:

```ts
import '@astryx-vue/themes/neutral.css'
```

### Anatomy

- **Label**: Text identifying the multi-line field.
- **Description**: Helper text between the label and the input.
- **Input container**: Painted boundary containing the text area and its overlays.
- **Text area**: Multi-line control that displays and edits the value.
- **Placeholder**: Hint text shown inside the empty text area.
- **Start icon**: Astryx Icon rendered at the start when startIcon is a semantic name or icon component.
- **Custom start content**: Caller-provided slot content rendered at the start instead of an Astryx Icon.
- **Spinner**: Loading indicator shown at the end of the input container.
- **Status icon**: Error, warning, or success icon shown inside the input.
- **Character counter**: Current and maximum character counts shown inside the input container.
- **Field status message**: Attached or detached error, warning, or success message associated with the field.
- **Tooltip status message**: Tooltip surface presenting the status message for the tooltip variant.

## Best practices

| Guidance | Practices |
| --- | --- |
| Do | Provide a visible label so users know what to enter. If the label must be hidden, set isLabelHidden with a descriptive label for screen readers. |
| Do | Set maxLength with a character counter when there is a defined limit; it helps users stay within bounds before they submit. |
| Do | Use the status prop to surface validation feedback inline: show success when input is valid, warning for soft limits, and error for hard failures. |
| Do | Add a description or placeholder to clarify expected content, like "Describe the issue in detail," but never rely on placeholder alone as the only label. |
| Don't | Avoid using TextArea for short, single-line values like names or emails; use TextInput instead. |
| Don't | Don't rely solely on placeholder text to communicate the purpose of the field; placeholders disappear on focus and are not accessible labels. |
| Don't | Don't show a status message without also setting the status type; the colored border and icon are what draw the user's attention to the message. |
| Don't | Don't wrap a disabled TextArea in Tooltip to explain why it's disabled; disabled controls swallow the hover events the wrapper needs. Use the disabledMessage prop instead. |

## Examples

### Character count

A status update with a 280-character limit and a live counter.

```vue
<script setup lang="ts">
import { TextArea } from '@astryx-vue/core/TextArea'
import { ref } from 'vue'

const value = ref('Excited to announce that our team just shipped the new dashboard! Check it out and let us know what you think.')
</script>

<template>
  <div style="width: 400px; max-width: 100%">
    <TextArea
      v-model="value"
      label="Status update"
      placeholder="What's on your mind?"
      :maxlength="280"
      :rows="3"
    />
  </div>
</template>
```

### States

Required, disabled, and loading fields.

```vue
<script setup lang="ts">
import { VStack } from '@astryx-vue/core/Stack'
import { TextArea } from '@astryx-vue/core/TextArea'
import { ref } from 'vue'

const requiredValue = ref('')
const disabledValue = ref('This field is disabled and cannot be edited.')
const loadingValue = ref('')
</script>

<template>
  <VStack :gap="4" width="100%" style="max-width: 400px">
    <TextArea v-model="requiredValue" label="Required field" placeholder="Describe the issue..." is-required />
    <TextArea v-model="disabledValue" label="Disabled field" is-disabled />
    <TextArea v-model="loadingValue" label="Loading field" placeholder="Generating summary..." is-loading />
  </VStack>
</template>
```

### Validation

Error, warning, and success messages, plus an error with no message.

```vue
<script setup lang="ts">
import { VStack } from '@astryx-vue/core/Stack'
import { TextArea } from '@astryx-vue/core/TextArea'
import { ref } from 'vue'

const errorValue = ref('Fix the')
const warningValue = ref('Summarize the Q2 results')
const successValue = ref('Redesign the onboarding flow to reduce drop-off by 15% in Q3. Focus on simplifying the account creation step and adding a progress indicator.')
const errorNoMsgValue = ref('Invalid content')
</script>

<template>
  <VStack :gap="4" width="100%" style="max-width: 400px">
    <TextArea
      v-model="errorValue"
      label="Error message"
      :status="{ type: 'error', message: 'Description must be at least 20 characters.' }"
    />
    <TextArea
      v-model="warningValue"
      label="Warning message"
      :status="{ type: 'warning', message: 'Consider adding more detail for clarity.' }"
    />
    <TextArea
      v-model="successValue"
      label="Success message"
      :status="{ type: 'success', message: 'Looks good — clear and actionable.' }"
    />
    <TextArea
      v-model="errorNoMsgValue"
      label="Error without message"
      :status="{ type: 'error' }"
    />
  </VStack>
</template>
```

### Icon

Meeting notes with a pencil icon and a short description.

```vue
<script setup lang="ts">
import { TextArea } from '@astryx-vue/core/TextArea'
import { ref } from 'vue'

const value = ref('')
</script>

<template>
  <div style="width: 400px; max-width: 100%">
    <TextArea
      v-model="value"
      label="Meeting notes"
      description="Capture key decisions and action items."
      placeholder="What was discussed?"
    >
      <template #icon>
        <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="1.5" aria-hidden="true">
          <path stroke-linecap="round" stroke-linejoin="round" d="m16.862 4.487 1.687-1.688a1.875 1.875 0 1 1 2.652 2.652L10.582 16.07a4.5 4.5 0 0 1-1.897 1.13L6 18l.8-2.685a4.5 4.5 0 0 1 1.13-1.897l8.932-8.931Zm0 0L19.5 7.125" />
        </svg>
      </template>
    </TextArea>
  </div>
</template>
```

## Keyboard controls

The control is a real `textarea`, so it keeps the browser's native key behaviour, and the component only adds handling on top of a few keys. Most keystrokes therefore behave exactly as they do in any other multi-line field:

- Tab moves focus into or out of the text area.
- Shift + Enter inserts a newline at the caret.
- Enter emits the `enter` event, so your handler can take over submit-like logic.
- Escape closes an open disabled reason tooltip or status tooltip.

When submit-on-Enter behaviour makes sense for your form, implement it in the `enter` handler.

## Usage guidance

The text area does not constrain what users type, so length limits and validation belong to your application:

- When the expected length matters, state `minlength` and `maxlength` in the `description` so users know it before they submit.
- `isRequired` only shows the required indicator and sets the matching ARIA state; it does not run native validation.
- Whether the content meets your business rules is up to validation in application code.

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `v-model` | `string` | — | Required. Text content. |
| `label` | `string` | — | Required. Field name. |
| `id` | `string` | — | Prefix for associated IDs. Auto-generated when omitted. |
| `size` | `'sm' \| 'md' \| 'lg'` | md | Text area height. |
| `rows` | `number` | — | Native textarea rows. |
| `cols` | `number` | — | Native textarea cols. |
| `minlength` | `number \| string` | — | Native textarea minlength. |
| `maxlength` | `number \| string` | — | Visible-character limit. One emoji counts as one. Typing past it stays allowed; the count turns red, and screen readers hear the near and over zones. It is not written to the native maxlength attribute. |
| `wrap` | `'soft' \| 'hard'` | soft | Native textarea wrap. |
| `resize` | `'none' \| 'both' \| 'horizontal' \| 'vertical'` | vertical | Native textarea resize. Vertical dragging is enabled by default. |
| `autoComplete` | `string` | — | Native textarea autocomplete token, such as `off` or `email`. Forwarded unchanged; the controlled value is not affected. |
| `hasSpellCheck` | `boolean` | true | Turns the browser spell checker on or off for the textarea. |
| `placeholder` | `string` | — | Placeholder text. |
| `description` | `string` | — | Description below the label. |
| `isLabelHidden` | `boolean` | false | Hide the visual label. Keep the accessible name. |
| `isDisabled` | `boolean` | false | Prevent edits. Do not submit the form value. |
| `disabledMessage` | `string` | — | Reason for disabling. The disabled text area stays focusable when provided. |
| `isReadOnly` | `boolean` | false | Prevent edits. Include the value in form submission. |
| `isRequired` | `boolean` | false | Show a required description. Does not run native required validation. |
| `isOptional` | `boolean` | false | Show an optional description. Takes precedence over isRequired. |
| `requiredLabel` | `string` | Required | Required description text. |
| `optionalLabel` | `string` | Optional | Optional description text. |
| `width` | `number \| string` | — | Width of the whole field. Numbers are treated as px. |
| `htmlName` | `string` | — | Native textarea name. |
| `form` | `string` | — | ID of the associated form. |
| `status` | `FieldStatusInput` | — | Error, warning, or success status. |
| `statusVariant` | `'attached' \| 'detached' \| 'tooltip'` | detached | How the status message is displayed. Text area defaults to below the control. |
| `changeAction` | `(value: string, event) => void \| Promise<void>` | — | Action to run after content changes. |
| `isLoading` | `boolean` | false | Show a loading indicator. |
| `hasClear` | `boolean` | false | Show a clear button. |
| `hasAutoFocus` | `boolean` | false | Focus on mount. |
| `clearLabel` | `string` | — | Accessible name of the clear button. It includes the field label by default. The tooltip only says “Clear”. |
| `containerClass` | `string \| object \| array` | — | Class for the field container. Has no effect, and warns in development, inside InputGroup and in a horizontal-labels FormLayout. |
| `containerStyle` | `StyleValue` | — | Inline style for the field container. |
| `controlClass` | `string \| object \| array` | — | Class for the text area box. A class written on the component lands here too, with no warning. |
| `controlStyle` | `StyleValue` | — | Inline style for the text area box. A style written on the component lands here too. |
| `loadingLabel` | `string` | Loading | Accessible label for the loading indicator. |
| `labelIcon` | `Component` | — | Decorative icon before the label. |
| `labelTooltip` | `string` | — | Info tooltip beside the label. |

## Events

- `update:modelValue(value)`：update text content.
- `change(value, event)`：fired when content changes.
- `clear(event)`：fired when the clear button is clicked.
- `enter(event)`：fired on Enter. Shift + Enter does not fire it.
- `keydown(event)`：fired on any key press.
- `actionError(error, value, event)`：fired when changeAction throws.

When content changes, `update:modelValue` and `change` fire before `changeAction`.
Cancelling the `change` event prevents `changeAction` from running.

## Native attributes

- `class`, `style`, and other attributes are applied to the field wrapper.
- `aria-labelledby` and `aria-describedby` are merged into the native textarea.
- `focus`, `blur` and `paste` listeners land on the native textarea.
- The component manages `disabled`, `readonly`, `spellcheck`, and `aria-invalid`.
- The `icon` slot shows a decorative icon on the left.
- The `end` slot shows extra content on the right.
- The `labelIcon` slot replaces the icon before the label.

## Theming

```css
.my-text-area {
  --astryx-text-area-min-height-md: 120px;
}
```

- `--astryx-text-area-min-height-sm`: minimum height for the sm size.
- `--astryx-text-area-min-height-md`: minimum height for the md size.
- `--astryx-text-area-min-height-lg`: minimum height for the lg size.

Other color and border variables are shared with TextInput. Neutral adapts to light and dark modes.
