# Textarea

> A Textarea widget to allow user to enter multi-line string chains

Textarea widgets are [Input Fields](https://golemui.com/dx/widgets-reference/input-fields/overview.md) that allow the user to enter multi-line string chains.


```ts title="textarea.ts"

export default [
  gui.inputs.textarea('comments', {
    label: 'Comments',
  }),
];
```

_Live demo on the docs page. Form definition: [textarea.ts](https://golemui.com/template/widgets-dx/textarea/textarea.ts)._

## Props

Use these `props` to customize your Textarea widget.

| prop            | type    | description                                                                                                            |
| --------------- | ------- | ---------------------------------------------------------------------------------------------------------------------- |
| `autocomplete`  | string  | `'on'`, `'off'`, or a space-separated list of W3C autofill tokens                                                      |
| `autoGrow`      | boolean | If true, the textarea will automatically expand its height as the user types                                           |
| `counterMode`   | string  | Mode for the character counter if `validator.maxLength` is set, possible values are `remaining` (default) or `current` |
| `hint`          | string  | A description to display below the textarea                                                                            |
| `minimumHeight` | number  | Minimum height of the textarea in pixels, defaults to 120                                                              |
| `placeholder`   | string  | A placeholder text to display when the textarea has no value                                                           |

### Placeholder

Use the property `placeholder` to add a placeholder.


```ts title="textarea.ts"

export default [
  gui.inputs.textarea('comments', {
    placeholder: 'Enter your comments here...',
    label: 'Comments',
  }),
];
```

_Live demo on the docs page. Form definition: [textarea-placeholder.ts](https://golemui.com/template/widgets-dx/textarea/textarea-placeholder.ts)._

### Hint

<Aside>A `label` is required for the `hint` to be displayed.</Aside>

Use the property `hint` to add a description.


```ts title="textarea.ts"

export default [
  gui.inputs.textarea('comments', {
    hint: 'Please be descriptive.',
    label: 'Comments',
  }),
];
```

_Live demo on the docs page. Form definition: [textarea-hint.ts](https://golemui.com/template/widgets-dx/textarea/textarea-hint.ts)._

### Character Counter

Use the validator `maxLength` to limit the number of characters and display a character counter. You can change how it counts with `counterMode` (`remaining` or `current`).

The limit doesn't block input. The user can type or paste past it, the counter shows the value is over the limit, and the input shows the `maxLength` error. The `maxLength` prop is deprecated: see [Deprecated props](#deprecated-props).


```ts title="textarea.ts"

export default [
  gui.inputs.textarea('commentsRemaining', {
    counterMode: 'remaining',
    label: 'Comments',
    validator: {
      maxLength: 10,
      required: true,
    },
  }),
  gui.inputs.textarea('commentsCurrent', {
    counterMode: 'current',
    label: 'Comments',
    validator: {
      maxLength: 10,
      required: true,
    },
  }),
];
```

_Live demo on the docs page. Form definition: [textarea-counter.ts](https://golemui.com/template/widgets-dx/textarea/textarea-counter.ts)._

### Auto Grow

Use the property `autoGrow` to allow the textarea to expand automatically based on content. You can combine it with `minimumHeight` to set its initial size.


```ts title="textarea.ts"

export default [
  gui.inputs.textarea('comments', {
    autoGrow: true,
    minimumHeight: 50,
    label: 'Comments',
  }),
];
```

_Live demo on the docs page. Form definition: [textarea-autogrow.ts](https://golemui.com/template/widgets-dx/textarea/textarea-autogrow.ts)._

## Deprecated props

This prop has no effect, and v3.0.0 removes it:

| Deprecated  | Use instead                                                     |
| ----------- | --------------------------------------------------------------- |
| `maxLength` | `validator.maxLength`, which controls the counter and the error |

## Styling

Textareas can be styled as explained in the [Styling Guide](https://golemui.com/dx/styling/overview.md).

### CSS Variables

Following you will find a list with the CSS Variables and a quick description of what you will style.

| CSS Variable             | Description                                     |
| ------------------------ | ----------------------------------------------- |
| `--gui-font-sm`          | Counter text font size                          |
| `--gui-space-2`          | Counter top margin                              |
| `--gui-intent-error`     | Counter error color when max length is exceeded |
| `--gui-space-gap--inner` | Label gap and margin bottom                     |
| `--gui-padding`          | Input padding                                   |
| `--gui-color-border`     | Input border color                              |
| `--gui-radius`           | Input radius                                    |
| `--gui-color-bg`         | Input background color                          |
| `--gui-color-fg`         | Input text color                                |
| `--gui-color-primary`    | Input border color and outline on focus         |
| `--gui-color-error`      | Input border color when invalid                 |

### Anatomy

This is the anatomy of the Textarea Widget in case you want to use your CSS styles.


```html title="textarea-anatomy.html"
<gui-textarea-input class="gui-textarea gui-field">
  <gui-textarea class="gui-field">
    <label class="gui-label" for="fieldUid" id="fieldUid_label">
      <span class="gui-label__text">Label</span>
      <div class="gui-widget-hint" id="fieldUid_hint" aria-hidden="true">Hint</div>
    </label>

    <div class="gui-widget">
      <textarea
        class="gui-widget-input"
        id="fieldUid"
        placeholder="Custom placeholder"
        aria-describedby="fieldUid_hint"
        style="height: 120px; min-height: 120px"
      ></textarea>
    </div>

    <div class="gui-textarea--validation">
      <div>
        <div class="gui-validator gui-validator--empty" id="fieldUid_errors" role="alert"></div>
      </div>
      <div class="gui-textarea--counter">
        <span>0</span>
        <span>/ 100</span>
      </div>
    </div>
  </gui-textarea>
</gui-textarea-input>
```
