> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# `<textarea>`

A multi-line text field, like a `<textarea>`. For a single line, use [`<input>`](/api/elements/input.md).


## Usage

```typescript title="src/app/message.ts"
import { Component, signal } from '@angular/core';
import { LYNX_ELEMENTS } from '@blotch/angular-lynx';

@Component({
  selector: 'app-message',
  imports: [LYNX_ELEMENTS],
  template: `
    <textarea
      placeholder="Write a message"
      maxlines="6"
      (bindinput)="text.set($event.detail.value)"
    ></textarea>
  `,
})
export class Message {
  readonly text = signal('');
}
```

Import `LYNX_ELEMENTS` in your component (see [Elements](/api/angular-lynx/elements/index.md)).

Lynx draws a field with no border, as tall as its text. Size and outline it with classes, such as `class="h-[120px] rounded-lg border border-zinc-200 px-3"`, or with `style`.

:::warning
Needs [XElement](/guide/glossary.md#xelement) in custom native apps (see [Embedding](/guide/embedding/index.md)).
:::

## Attributes

| Attribute                  | Type                                                | Default  | Description                                                                                                                                                               |
| -------------------------- | --------------------------------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `type`                     | `'text' \| 'number' \| 'digit' \| 'tel' \| 'email'` | `'text'` | What can be typed, and which on-screen keyboard opens.                                                                                                                    |
| `placeholder`              | `string`                                            | —        | Hint shown while the field is empty. On iOS it stays visible over text set from code, so drop it while there's a value: `[attr.placeholder]="text() ? null : 'Message'"`. |
| `value`                    | `string`                                            | —        | The text the field shows, from its first render and whenever code changes it, such as to clear the field. Bind it as `[value]`: see [Bind the value](#bind-the-value).    |
| `default-value`            | `string`                                            | —        | iOS and Android. Text on the first render only. It doesn't fire `bindinput`.                                                                                              |
| `maxlength`                | `number`                                            | No limit | Maximum number of characters.                                                                                                                                             |
| `maxlines`                 | `number`                                            | —        | iOS and Android. Maximum number of lines.                                                                                                                                 |
| `line-spacing`             | `number \| string`                                  | —        | iOS and Android. Extra space between lines, e.g. `4` or `'4px'`.                                                                                                          |
| `confirm-type`             | `'send' \| 'search' \| 'go' \| 'done' \| 'next'`    | `'done'` | Label of the keyboard's return key. `bindconfirm` fires only when you set it.                                                                                             |
| `readonly`                 | `boolean`                                           | `false`  | The text can't be edited.                                                                                                                                                 |
| `disabled`                 | `boolean`                                           | `false`  | The field is fully inert: no focus and no keyboard.                                                                                                                       |
| `input-filter`             | `string`                                            | —        | A regular expression each typed character must match.                                                                                                                     |
| `show-soft-input-on-focus` | `boolean`                                           | `true`   | iOS and Android. Opens the on-screen keyboard when the field gets focus.                                                                                                  |
| `bounces`                  | `boolean`                                           | `true`   | iOS only. Bounce when its content scrolls past the edges.                                                                                                                 |
| `enable-scroll-bar`        | `boolean`                                           | `false`  | iOS and Android. Shows the scroll bar.                                                                                                                                    |
| `ios-auto-correct`         | `boolean`                                           | `true`   | iOS only. Autocorrect.                                                                                                                                                    |
| `ios-spell-check`          | `boolean`                                           | `true`   | iOS only. Spell checking.                                                                                                                                                 |
| `android-fullscreen-mode`  | `boolean`                                           | `true`   | Android only. In landscape, the keyboard and the field fill the screen.                                                                                                   |

Plus the [common attributes](/api/elements/view.md#attributes), such as `id` and `class`.

### Bind the value

- **Bind `value` as `[value]`.** iOS and Android have no `value` attribute.
- **AngularLynx sets the text for you,** with `setValue`, or as `default-value` before the field is on screen.
- **`[attr.value]` skips that and doesn't work.**

## Events

Read the payload from `$event.detail`. Angular types `$event` for each event: see [Element events](/api/angular-lynx/element-events.md#input-and-textarea).

| Event                      | `detail`                                                                                    | Description                                                                                                                                                                            |
| -------------------------- | ------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `bindinput`                | `{ value: string; selectionStart: number; selectionEnd: number; isComposing?: boolean }`    | The text changed. `isComposing` is `true` while a keyboard that builds characters from several keystrokes is mid-character.                                                            |
| `bindfocus`                | `{ value: string }`                                                                         | The field got focus.                                                                                                                                                                   |
| `bindblur`                 | `{ value: string }`                                                                         | The field lost focus.                                                                                                                                                                  |
| `bindconfirm`              | `{ value: string }`                                                                         | The user pressed the keyboard's return key. Fires only when `confirm-type` is set.                                                                                                     |
| `bindselection`            | `{ selectionStart: number; selectionEnd: number }`                                          | The cursor or the selection moved.                                                                                                                                                     |
| `bindbeforeinput`          | `{ value: string; cursor: number; length: number; replace: string; isComposing?: boolean }` | iOS only. An edit is about to replace `length` characters from `cursor` with `replace`. `value` is the text before it.                                                                 |
| `bindkeyboardheightchange` | `{ height: number }`                                                                        | iOS and Android. The keyboard showed, changed size or hid (`0`) while the field has focus. iOS: points from the window's bottom. Android: physical pixels from the Lynx view's bottom. |
| `bindkeyboard`             | `{ show: boolean; keyboardHeight?: number; safeAreaBottom?: number }`                       | iOS only. The keyboard is showing or hiding. As it shows, it also sends its height and the bottom safe-area inset, in points.                                                          |
| `bindline`                 | `{ line: number }`                                                                          | The number of lines changed. On iOS and Android, `-1` means an edit would have gone over `maxlines`.                                                                                   |

Plus the [common events](/api/elements/view.md#events), such as `bindtap`.

## Methods

These **UI methods** ([Glossary](/guide/glossary.md#ui-method)) control the field from code. Call them with `invoke()` on the element (see [Call element methods](/guide/selector-query.md)). A call from a handler returns nothing: to read a result, call `invoke()` in a main-thread script instead.

| Method              | Parameters                                         | Description                                                     |
| ------------------- | -------------------------------------------------- | --------------------------------------------------------------- |
| `focus`             | —                                                  | Focuses the field and opens the keyboard.                       |
| `blur`              | —                                                  | Removes focus and closes the keyboard.                          |
| `getValue`          | —                                                  | Returns `{ value, selectionStart, selectionEnd, isComposing }`. |
| `setValue`          | `{ value: string }`                                | Replaces the text. A `[value]` binding calls this for you.      |
| `setSelectionRange` | `{ selectionStart: number; selectionEnd: number }` | Selects a range of characters. Equal values place the cursor.   |

```typescript
import { Component, ElementRef, viewChild } from '@angular/core';
import { LYNX_ELEMENTS } from '@blotch/angular-lynx';

@Component({
  selector: 'app-note',
  imports: [LYNX_ELEMENTS],
  template: `
    <textarea #note placeholder="Note"></textarea>
    <view (bindtap)="done()"><text>Done</text></view>
  `,
})
export class Note {
  readonly note = viewChild.required('note', { read: ElementRef });

  done(): void {
    // Closes the on-screen keyboard.
    this.note().nativeElement.invoke?.('blur');
  }
}
```

## Related

- [Forms](/guide/forms.md): reactive forms, validation and the on-screen keyboard
- [`<input>`](/api/elements/input.md)
- [Textarea](/dolan/textarea.md): the styled UI component
