For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /dolan/textarea.md.

Textarea

A multi-line text field that grows with its content, with an optional label, helper text and error message.

Installation

npx @blotch/dolan add textarea
import { UiTextarea } from '../components/ui/textarea';

Usage

src/app/app.ts
import { Component, signal } from '@angular/core';
import { UiTextarea } from '../components/ui/textarea';

@Component({
  selector: 'app-root',
  imports: [UiTextarea],
  template: `
    <ui-textarea
      label="Bio"
      placeholder="Tell us about yourself"
      [(value)]="bio"
    />
  `,
})
export class App {
  protected readonly bio = signal('');
}
  • [(value)] updates your signal on every keystroke. Setting the signal from code updates the field too.
  • The field opens three lines tall and grows as the user types.
  • class styles the whole block of label, field and message.

Height limits

<ui-textarea label="Review" [minLines]="3" [maxLines]="6" [(value)]="review" />
<ui-textarea label="Note" [minLines]="1" [maxLines]="4" [(value)]="note" />
  • minLines sets the starting height.
  • maxLines stops the growth. Past it, the field scrolls and shows a scroll bar. Without it, the field keeps growing.
  • Each line is 20 pixels, the line height of the field's text.

Helper text and errors

<ui-textarea
  label="Feedback"
  helperText="Helps us improve"
  [(value)]="feedback"
/>
<ui-textarea
  label="Description"
  error="Description is required"
  [(value)]="description"
/>

A non-empty error replaces the helper text with red text and turns the focus ring red. The field shakes when an error first appears.

Disabled

<ui-textarea label="System notes" value="Read only" disabled />

Signal Forms

UiTextarea implements Angular's FormValueControl, so [formField] works on it the same way as on Input. It emits touch when the field loses focus, so the field counts as touched and an error can show as soon as the user leaves it, as on an input. A form's maxLength() and readonly() reach the field, and focusBoundControl() focuses it.

API

UiTextarea

InputTypeDefaultDescription
valuestring''The text. Supports [(value)].
labelstring''Text above the field. Hidden when empty.
accessibility-labelstring''The field's name for screen readers when it has no label.
placeholderstring''Hint shown while the field is empty.
helperTextstring''Muted text under the field. Hidden while error is set.
errorstring''Error text. Turns the ring red and shakes the field.
disabledbooleanfalseDims the field and ignores typing.
minLinesnumber3Starting height, in lines.
maxLinesnumber | undefinedundefinedHeight at which the field stops growing and scrolls.
classstring''Extra Tailwind classes for the outer block.
maxLengthnumber—The most characters the field takes. Signal Forms sets it from maxLength().
readonlybooleanfalseThe text can't be changed. Signal Forms sets it from readonly().
OutputTypeDescription
valueChangestringEmits the text on every keystroke, for [(value)].
changedstringEmits the text on every keystroke.
focusedvoidEmits when the field gains focus.
blurredvoidEmits when the field loses focus.
touchvoidEmits when the field loses focus, for forms.

Accessibility

  • A screen reader reads the field with its label, which becomes the native <textarea>'s accessibility-label, and then the text in it. The label above the field isn't a stop of its own, so it isn't read twice.
  • A field without a label takes its name from accessibility-label, for a textarea under a label of your own. Without either, a screen reader reads only the placeholder. label wins when both are set.
  • Tests find it by its label too: getByRole('textbox', { name: 'Notes' }) returns the <textarea>.
  • Input: a single-line field
  • Forms: forms and the on-screen keyboard
  • <textarea>: the element underneath