Create

Form

Textarea

Copy page View as Markdown Open in ChatGPT Open in Claude

Displays a form textarea or a component that looks like a textarea.

Usage#

app.component.ts
import { WdsTextareaComponent } from '@wds/angular/textarea';

Examples#

Default#

The textarea grows with its content (field-sizing: content), from a minimum height of 64px.

Field#

In wds-field the label and the description become the accessible name and description of the textarea.

Message Enter your message below.

Disabled#

Message

Invalid#

invalid on wds-field or on the textarea shows the error state.

Message Please enter a valid message.

Button#

Send message

Forms#

Integration with Angular forms. Pick the API your app uses.

Signal forms#

WdsTextField connects the textarea to [formField]. Validators from the schema (required, minLength, maxLength) also set the matching attributes of the native textarea. wds-field-error shows the errors() of the field.

BioAt least 10 and at most 160 characters.Submit

Submitted: —

Template-driven#

WdsTextValueAccessor makes ngModel work on wds-textarea. Angular validators (required, minlength, maxlength) work as on a native textarea; maxlength also stops typing at the limit.

BioAt least 10 and at most 160 characters.Submit

Submitted: —

Reactive forms#

The same WdsTextValueAccessor works with formControl and formControlName.

BioAt least 10 and at most 160 characters.Submit

Submitted: —

API References#

wds-textarea#

Multi-line text field. It grows with its content (field-sizing: content), min. 64px.

Attributes

AttributeTypeDefaultDescription
rowsnumber | undefinedInitial number of rows (when the browser does not support field-sizing).
valuestring''Current value.
namestring''Field name in the form. Reflected to the attribute, which FormData uses (also when a framework sets it as a property).
placeholderstring''Text shown while the field is empty.
disabledbooleanfalseDisables the field and excludes it from form submission.
readonlybooleanfalseThe value can be read and selected, but not changed.
requiredbooleanfalseA value is required for the form to be valid.
invalidbooleanfalseError state: red border and aria-invalid.
autocompletestring''Native autocomplete hint.
minlength.minLengthnumber | undefinedMinimum length of the value (native validation).
maxlength.maxLengthnumber | undefinedMaximum length of the value.

Events

EventDescription
wds-inputCustomEvent<WdsTextChangeDetail>Every change of the value.
wds-changeCustomEvent<WdsTextChangeDetail>A committed change (blur).

Methods

MethodDescription
select()Selects all text.
formResetCallback()
formDisabledCallback(disabled: boolean)
formStateRestoreCallback(state: string | File | FormData | null)
checkValidity()Returns true when the value is valid; otherwise fires invalid on the element.
reportValidity()Like checkValidity(), and shows the browser validation bubble when the value is invalid.
setCustomValidity(message: string)Sets a custom validation error (an empty string clears it), like input.setCustomValidity().

CSS parts (::part)

PartDescription
controlThe native <textarea>.

Accessibility#

Screen reader#

wds-textarea renders a native <textarea>, so it is announced as a multi-line edit field. Without wds-field give it a name with aria-label on the element: it is forwarded to the native textarea.

In wds-field, wds-field-label names the textarea and wds-field-description describes it. invalid sets aria-invalid="true"; disabled, readonly and required are set on the native textarea.

The textarea takes part in forms: its value is submitted under name, and required, minlength and maxlength work as native validation.

Keyboard support#

KeyFunction
TabMoves focus to the textarea. A disabled textarea is skipped.
EnterInserts a new line.
Footer