Textarea
A multi-line text field that grows with its content, with an optional label, helper text and error message.
Installation
Usage
src/app/app.ts
[(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.
classstyles the whole block of label, field and message.
Height limits
minLinessets the starting height.maxLinesstops 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
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
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
Accessibility
- A screen reader reads the field with its
label, which becomes the native<textarea>'saccessibility-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
labeltakes its name fromaccessibility-label, for a textarea under a label of your own. Without either, a screen reader reads only the placeholder.labelwins when both are set. - Tests find it by its label too:
getByRole('textbox', { name: 'Notes' })returns the<textarea>.
Related
- Input: a single-line field
- Forms: forms and the on-screen keyboard
<textarea>: the element underneath
